I am stuck with one problem that i have one MultiAutoCompleteTextView
as shown in below image:
In that i am selecting city name from suggestion of MultiAutoCompleteTextView
and adding that item in ListView
(as below). I want to prevent to enter other entries rather than ADAPTER
values.
I am binding code this way and onClick
of Button
I am separating values by comma:
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);
}
});
}
}
I am thinking to check entered values with Database by SELECT Query but i have 75000+ records so its difficult solution for this.
Any Help? It will be Appreciated.
One way is to remove the possibility to write inside the AutoCompleteTextView with:
And onTouch call show adapter, that will show the list of cities.