I have an adapter in which there are some values. I can choose one of this value from a AutoCompleteTextView and then i can pass the value in a next activity when i click on a button. Typing something it shows the possible result. Of course, if i click on one of them it adds the value in the AutoCompletetextView and this is the code so far:
firstAutocomplete.setAdapter(adapter);
firstAutocomplete.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
firstAutocomplete.showDropDown();
}
});
firstAutocomplete.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
itemFirst = adapter.getItem(arg2);
}
});
The adapter of course contains the values. It works normally in this way. My problem now is that i can save the value i choose in a sqLite db and i shows this value in a dynamic listview. What i want is that if i click a listview item it add that value on the AutoCompleteTextView so i can easily go to next activity without typing each time.
Problem: If i do in this way:
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Cursor cursor = (Cursor) parent.getItemAtPosition(position);
String item_first = cursor.getString(cursor.getColumnIndex(mdb.KEY_FIRST));
firstAutocomplete.setText(item_first);
}
});
and the i click the button tha app crashes because seems that the value firstAutocomplete.setText(item_first); is null.
My question is: Is the problem due to the fact that the setText not is "forced" and not a value directly choose from the adapter and so it found a null string? How can i solve?
Aucun commentaire:
Enregistrer un commentaire