Answer the question
In order to leave comments, you need to log in
Glitch getText() in AutoCompleteTextView?
In the onItemClick event for the AutoCompleteTextView, you need to get the text of the AutoCompleteTextView itself.
It doesn't work for me, AutoCompleteTextView.getText().toString() returns some nonsense:
AutoCompleteTextView mEditText = (AutoCompleteTextView) findViewById(R.id.myEditText);
mEditText.setAdapter(new MyAdapterCompleteItem()); // adapter with CompleteItems
mEditText.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
CompleteItem myitem = (CompleteItem) adapterView.getItemAtPosition(position);
String str = mEditText.getText().toString();
// здесь str == ‘[email protected]'
}
}
});
Answer the question
In order to leave comments, you need to log in
I don't quite understand what you need? if you need the text that became in the AutoCompleteTextView after clicking, then isn't it easier to call the getItem method in the adapter?
final AutoCompleteTextView mEditText = (AutoCompleteTextView) findViewById(R.id.my_edit_text);
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, COUNTRIES);
mEditText.setAdapter(adapter); // adapter with CompleteItems
mEditText.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
String myitem = (String) adapterView.getItemAtPosition(position);
String str = mEditText.getText().toString();
String item = adapter.getItem(position);
Log.d("ITEM = ", myitem);
Log.d("STR = " , str);
Log.d("ITEM IS = ", item);
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question