I’m developing an android application in which I retrieve some piece of data ( all the village village names) from SQLite database table. I returned this via String Array. Code is
public String[] getAllVillage()
{
String[] villagelist=new String[2000];
int i=0;
Cursor c=sqLiteDatabase.rawQuery("SELECT * FROM " + MYDATABASE_TABLE2 ,null);
if (c.moveToFirst())
{
do
{
villagelist[i]=c.getString(1);
i++;
}while(c.moveToNext());
}
c.close();
return villagelist;
}
and, In my android application I passed this array into AutoCompleteTextview as following:
private SQLiteAdapterv vadapter;
String[] village=new String[2000];
String newone[] = new String[2000];
village=vadapter.getAllVillage();
for(int h=0;h<2000;h++)
{
newone[h]=village[h];
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,newone);
final AutoCompleteTextView acTextView = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
acTextView.setThreshold(0);
acTextView.setAdapter(adapter);
acTextView.addTextChangedListener(this);
But the code has no effect which means, when I click the AutocompleteTextview, it won’t show any villagenames. Is my method was correct? If not then help me to do this
First, the problem in your code is
The reason is assume that if only 1000 records are present in your database. these two string arrays contains 1000 result and null values upto the remaining. You can check by breakpoint. AutoComplete Textview doesn’t support such format.
So you should make some changes in your code as
Then you can directly use village in setAdapter as