1

Android AutoCompleteTextView-Suche und gibt das Ergebnis in der Liste statt im Standard-Dropdownfeld zurück.Android AutoCompleteTextView-Ergebnis in der Liste anstelle des Standard-Dropdown-Menüs

Gibt es eine Möglichkeit, dass ich das Ergebnis einer AutoCompleteTextView neu entwerfen und in eine andere Liste als seine Standardliste Design legen konnte?

In meinem MainActivity, ich habe dies:

String[]fruits = {"apple", "avocado", "banana", "blackberry", "blueberry", "coconut", "durian", "mango", "melon"}; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    ArrayAdapter<String> stringArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.select_dialog_item, fruits); 

    AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.autocom); 
    autoCompleteTextView.setAdapter(stringArrayAdapter); 
    autoCompleteTextView.setTextColor(Color.RED); 

    ListView lv = (ListView) findViewById(R.id.lv); 
    lv.setAdapter(stringArrayAdapter); 

} 

In My xml,

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.example.android.autocompletenativesample.MainActivity"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginTop="15dp" 
     android:text="Pick a Fruit" 
     android:id="@+id/tv" 
     /> 
    <AutoCompleteTextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:id="@+id/autocom" 
     android:layout_below="@+id/tv" 
     android:layout_marginLeft="36dp" 
     android:layout_marginTop="17dp" 
     android:completionThreshold="1" 
     /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="ListView Implementation" 
     android:layout_below="@+id/autocom" 
     android:id="@+id/tv2" 
     /> 
    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/lv" 
     android:layout_below="@+id/tv2" 
     > 

    </ListView> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="RecyclerView Implementation" 
     android:layout_below="@+id/lv" 
     /> 
</RelativeLayout> 

Darüber hinaus hier eine Visual Explanation ist. Es wird im Feld AutoCompleteTextView gesucht, das Ergebnis wird jedoch nicht in einem anderen Layout angezeigt.

Soll ich den ArrayAdapter bearbeiten und das Layout ändern, oder eine CustomAutoCompleteTextView, die AutoCompleteTextView implementiert, und EditText, die AutoCompleteTextView implementiert.

Ich möchte für meine AutoCompleteTextView Ergebnis so formatiert werden. RecyclerView and CardView Result design

Danke.

Antwort