我正在處理自動完成文本視圖用於獲取匹配地方的需求。用戶必須輸入幾個字符,並從服務器返回與這些字符匹配的Localities列表。自動完成文本視圖然後應該顯示這個列表作爲下拉(或彈出)。出於某種原因,即使我從服務器接收到有效的地區信息,自動完成下拉菜單也不會出現。這是我的代碼。AutoCompleteTextView不顯示任何下拉菜單
局部性(型號)
public class Locality {
private int Id;
private String name;
private boolean selected;
//Getters and Setters
}
DonorSearchFragment.xml(含有AutoCompleteTextView佈局文件)
<AutoCompleteTextView
android:id="@+id/actLocality"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
LocalityListAdapter視圖(locality_row.xml)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
...
<TextView
android:id="@+id/txvLocalityName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
LocalityListAdapter.java
public class LocalityListAdapter extends ArrayAdapter<Locality> {
List<Locality> localities;
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//The Current View
View view = convertView;
if (view == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.locality_row, null);
}
Locality currentLocality = localities.get(position);
if (currentLocality != null) {
TextView txvLocalityName = (TextView) view.findViewById(R.id.txvLocalityName);
txvLocalityName.setText(currentLocality.getName());
}
return view;
}
}
DonorSearchFragment.java(片段表示AutoCompleteTextView)
在onPostExecute()我檢查,我接收有效地點列表,然後將它們推入支持適配器的LocalityList中,但這些地區不會通過下拉列表顯示。實際上沒有顯示下拉菜單。任何可能導致錯誤或遺漏的原因?