1

Android AutoCompleteTextView выполняет поиск и возвращает результат в списке вместо раскрывающегося списка по умолчанию.Android AutoCompleteTextView приводит к отображению списка, а не по умолчанию.

Есть ли способ, которым я мог бы редизайн и поместить результат AutoCompleteTextView в список, отличный от его списка по умолчанию?

В моей MainActivity, у меня есть это:

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); 

} 

В Мой 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> 

Кроме того, здесь Visual Explanation. Он будет искать в поле AutoCompleteTextView, но результат не будет отображаться ниже на другом макете.

Должен ли я изменить ArrayAdapter ang изменить макет или создать CustomAutoCompleteTextView, который реализует AutoCompleteTextView или EditText, который реализует AutoCompleteTextView.

Я хочу, чтобы мой результат AutoCompleteTextView был отформатирован следующим образом. RecyclerView and CardView Result design

Спасибо.

ответ

0

Я могу дать вам логику. проверьте эту ссылку. http://www.androidhive.info/2012/09/android-adding-search-functionality-to-listview/ и это тоже http://www.tutorialsbuzz.com/2014/08/android-filters-for-simple-listview.html

и Filteration делается в адаптере так первый связывает ListView с пустым адаптером и textWatcher bindlistview с источником данных и notifie фильтрованием для изменений.