【发布时间】:2015-10-03 18:33:01
【问题描述】:
我已经实现AutoCompleteTextView如下:
MainActivity.java
...
public static String[] myData=new String[]{"Africa (AF)","America (AFM)","Apple (AMP)"};
text=(AutoCompleteTextView)v.findViewById(R.id.first_state);
ArrayAdapter adapter = new ArrayAdapter(getActivity(),R.layout.autocompletetextview_row,R.id.textViewItem,myData);
text.setAdapter(adapter);
text.setThreshold(1);
text.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
selected_station = (String)parent.getItemAtPosition(position);
//TODO Do something with the selected text
}
});
在AutoCompleteTextView的布局中:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:padding="10dp" >
<TextView
android:id="@+id/textViewItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="Item name here..."
android:textColor="#000000"
android:textSize="20sp" />
</RelativeLayout>
当我键入“af..”时,它显示 非洲 (AF) 可供选择,但不显示 美国 (AFM)。
数据只是示例数据。并不是说我只使用AutoCompleteTextView 来处理 3 个项目。
编辑:当我删除括号时,它可以正常工作。但我需要保留括号以备将来使用。
【问题讨论】:
-
查看您的编辑后,我将删除我的答案:)。
标签: android android-arrayadapter autocompletetextview