1

Android AutoCompleteTextViewを検索し、デフォルトのドロップダウンではなくリストに結果を返します。Android AutoCompleteTextViewはデフォルトドロップダウンの代わりにListになります

AutoCompleteTextViewの結果をデフォルトのリストデザイン以外のリストに再デザインして入れられる方法はありますか?

<?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で、私のXMLで

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

} 

:私のMainActivityで

は、私はこれを持っています。 AutoCompleteTextViewフィールドで検索しますが、結果は別のレイアウトではなく下に表示されます。

ArrayAdapterを編集してレイアウトを変更するか、AutoCompleteTextViewを実装するCustomAutoCompleteTextView、およびAutoCompleteTextViewを実装するEditTextを作成する必要があります。

私のAutoCompleteTextViewのResultをこのようにフォーマットしたいと考えています。 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

とろ過はあなたの空のアダプタで、変更のためのデータソースのろ過とnotifieとtextWatcherのbindlistviewにアダプタので、最初のバインドリストビューで行われます。

関連する問題