I have example android app:
void fillAutoCompleteFromDatabase()
{
mCursor = mDB.query(
PetType.PETTYPE_TABLE_NAME,
new String[] {PetType.PET_TYPE_NAME,
PetType._ID}, null, null,
null, null,
PetType.DEFAULT_SORT_ORDER);
startManagingCursor(mCursor);
int iNumberOfSpeciesTypes = mCursor.getCount();
String astrAutoTextOptions[] = new String[iNumberOfSpeciesTypes];
if((iNumberOfSpeciesTypes > 0) && (mCursor.moveToFirst()))
{
for(int i = 0; i < iNumberOfSpeciesTypes; i++)
{
astrAutoTextOptions[i] =
mCursor.getString(mCursor.
getColumnIndex(PetType.PET_TYPE_NAME));
mCursor.moveToNext();
}
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(
this,
android.R.layout.simple_dropdown_item_1line,
astrAutoTextOptions);
AutoCompleteTextView text =
(AutoCompleteTextView)
findViewById(R.id.EditTextSpecies);
text.setAdapter(adapter);
}
}
I'm still learning Android and i have question - why i can add custom values from this array? I try:
void fillAutoCompleteFromDatabase()
{
mCursor = mDB.query(
PetType.PETTYPE_TABLE_NAME,
new String[] {PetType.PET_TYPE_NAME,
PetType._ID}, null, null,
null, null,
PetType.DEFAULT_SORT_ORDER);
startManagingCursor(mCursor);
int iNumberOfSpeciesTypes = mCursor.getCount();
String astrAutoTextOptions[] = new String[iNumberOfSpeciesTypes + 3];
if((iNumberOfSpeciesTypes > 0) && (mCursor.moveToFirst()))
{
for(int i = 0; i < iNumberOfSpeciesTypes; i++)
{
astrAutoTextOptions[i] =
mCursor.getString(mCursor.
getColumnIndex(PetType.PET_TYPE_NAME));
mCursor.moveToNext();
}
astrAutoTextOptions[iNumberOfSpeciesTypes + 1] = "aaaaaa";
astrAutoTextOptions[iNumberOfSpeciesTypes + 2] = "bbbb";
astrAutoTextOptions[iNumberOfSpeciesTypes + 3] = "cccccc";
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(
this,
android.R.layout.simple_dropdown_item_1line,
astrAutoTextOptions);
AutoCompleteTextView text =
(AutoCompleteTextView)
findViewById(R.id.EditTextSpecies);
text.setAdapter(adapter);
}
}
I dont have error in Eclipse, but if i open this app on my mobile phone then she crashed.
for loop.