我遇到了一个问题,MultiAutoCompleteTextView
如下图所示:
在那我从建议中选择城市名称MultiAutoCompleteTextView
并将该项目添加到ListView
(如下所示)。我想防止输入其他条目而不是ADAPTER
值。
我以这种方式绑定代码,并且onClick
我Button
用逗号分隔值:
private void initComp() { // GET DATA FROM DATABASE
multiSelectCities = (MultiAutoCompleteTextView) findViewById(R.id.activity_multiselect_city);
btnGetCity = (Button) findViewById(R.id.activity_btn_slect_city);
listCity = (ListView) findViewById(R.id.activity_get_city_list);
btnGetCity.setOnClickListener(this);
dbHelper = new DatabaseHelper(getApplicationContext());
dbHelper.open();
setName();
// dbHelper.close();
}
public void setName() { // FOR SET THE NAME IN MULTISELECT TEXTVIEW
final Cursor localcursor = dbHelper.getArea();
if ((localcursor != null) && (localcursor.getCount() > 0)) {
arrayOfString = new ArrayList < String > ();
localcursor.moveToFirst();
do {
arrayOfString.add(localcursor.getString(localcursor.getColumnIndex(DatabaseHelper.CITY_NAME)) + "-" + localcursor.getString(localcursor.getColumnIndex(DatabaseHelper.CITY_COUNTRY)));
} while (localcursor.moveToNext());
this.multiSelectCities.setThreshold(3);
adapter = new CityDataWithMultitextAdapter(this, arrayOfString);
multiSelectCities.setAdapter(adapter);
multiSelectCities.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
/* localcursor.close(); */
}
@Override
public void onClick(View v) { //SEARCH BUTTON CLICK AND STORE THE DATA INTO LISTVIEW
if (!Utils.isEmpty(multiSelectCities)) {
arrayList = multiSelectCities.getText().toString().substring(0, multiSelectCities.length() - 1).split(",");
for (int i = 0; i < arrayList.length; i++) {
selectedItems.add(arrayList[i].trim());
}
} else {
Utils.displayToast(this, "Please Enter City/Cities");
}
CityListAdapter adapter = new CityListAdapter(this, selectedItems);
listCity.setAdapter(adapter);
multiSelectCities.setText("");
listCity.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView <? > parent, View view, int position, long id) {
Intent i = new Intent(CityListDataActivity.this, CityListDetail.class);
i.putExtra("CITY_NAME", selectedItems.get(position).toString());
startActivity(i);
}
});
}
}
我正在考虑通过SELECT Query 使用数据库检查输入的值,但我有 75000 多条记录,因此很难解决这个问题。
有什么帮助吗?将不胜感激。