2011-12-13 60 views
9

這是我AutoCompleteTextView代碼:定做自動完成文本搜索建議列表

String[] countries = getResources().getStringArray(R.array.countries_array); 
    final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.item_list ,countries); 
    textView = (AutoCompleteTextView) dialog.findViewById(R.id.autoCompleteTextView1); 
    adapter.setNotifyOnChange(true); 
      textView.setAdapter(adapter); 

這是item_list:

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:padding="10dp" 
android:textSize="16sp" 
android:textColor="#000" 
android:drawableRight="@drawable/arrow"> 

,這是輸出:

enter image description here

我想改變這個彈出式的建議框,並且想要在AutoCompleteTextView下面顯示一些建議列表。(類似於這個):(請忽略蘋果設計,它只是關於結果出現的位置)

enter image description here

我怎樣才能做到這一點..Please建議。 謝謝。

+0

你能幫我這個嗎?http://stackoverflow.com/questions/29046302/how-to-implement-autocompletetextview-with-listview – 2015-03-16 09:55:45

回答

13

在佈局中使用android:dropDownAnchor,android:dropDownHorizontalOffset,android:dropDownVerticalOffset或其他人可能在AutoCompleteTextView上。見AutocompleteTextView

+0

謝謝..Done .. :) –

9

我在AutoCompleteTextView下面使用了一個ListView。我將我的自定義適配器添加到ListView和AutoCompleteTextView。我的設置高度和AutoCompleteTextView下拉列表的寬度爲0:

myListView.setAdapter(myCustomAdapter); 
myAutoComplete.setAdapter(myCustomAdapter); 
myAutoComplete.setDropDownHeight(0); 
myAutoComplete.setDropDownWidth(0); 

由於列表視圖也連接到同一個適配器,當您更新的自動完成,它會得到更新。

+0

我想我會去這個太..我找不到其他解決方案。 :/ – KarenAnne

+0

你能幫我這個http://stackoverflow.com/questions/29046302/how-to-implement-autocompletetextview-with-listview – 2015-03-16 09:56:14