2011-12-13 33 views
9

Đây là mã cho AutoCompleteTextView tôi:tùy chỉnh các Đề xuất Danh sách AutoComplete Lưu

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

Đây là 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"> 

và đây là kết quả:

enter image description here

Tôi muốn thay đổi loại hộp gợi ý bật lên này, và muốn hiển thị danh sách gợi ý một chút bên dưới từ AutoCompleteTextView ..similar về điều này: (hãy bỏ qua thiết kế của quả táo, nó chỉ là nơi kết quả xuất hiện)

enter image description here

Làm cách nào tôi có thể làm điều này ..Xin vui lòng đề xuất. Cảm ơn. !!

+0

bạn có thể giúp tôi với http://stackoverflow.com/questions/29046302/how-to-implement-autocompletetextview-with-listview –

Trả lời

13

Sử dụng android:dropDownAnchor, android:dropDownHorizontalOffset, android:dropDownVerticalOffset và có thể những người khác trên AutoCompleteTextView trong bố cục của bạn. Xem AutocompleteTextView.

+0

Thanks..Done .. :) –

9

Tôi đã sử dụng một ListView bên dưới AutoCompleteTextView. Tôi đã thêm bộ điều hợp tùy chỉnh của mình vào cả ListView và AutoCompleteTextView. Tôi các thiết lập chiều cao và chiều rộng của menu thả xuống AutoCompleteTextView 0:

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

Kể từ listview cũng được gắn vào cùng một bộ chuyển đổi nó sẽ được cập nhật khi bạn cập nhật tự động hoàn.

+0

Tôi nghĩ tôi sẽ làm điều này quá .. Tôi không thể tìm thấy giải pháp khác. :/ – KarenAnne

+0

bạn có thể giúp tôi với http://stackoverflow.com/questions/29046302/how-to-implement-autocompletetextview-with-listview này không –

Các vấn đề liên quan