I have an autocomplete text view in my app which worked as expected on android Jelybean and Kitkat but not at Lolipop. First the dropdown list doesn't appear at all at the first run of the Activity(after installation), but displayed okay from second time and then. But the most important is that when I select an item from the list, it doesn't get the correct value. Here is the related code:
mInput.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
Map<String, String> map = (Map<String, String>) parent
.getItemAtPosition(position);
Iterator<String> strInterator = map.keySet().iterator();
while(strInterator.hasNext()) {
String key=(String)strInterator.next();
String value = (String) map.get(key);
valueChar = parent.getItemAtPosition(position).toString();
String temp = valueChar.replace("{Name=", "");
valueChar = temp.substring(0, temp.indexOf(","));
valueNum = value.replaceAll("\\s", "");
Log.i("mInput text1:", mInput.getText().toString());
mInput.setText(valueNum);
Log.i("mInput text2:", mInput.getText().toString());
mInput.setSelection(mInput.getText().length());
Log.i("mInput text3:", mInput.getText().toString());
}
}
});
}
the list displays names and phone numbers. When I select an item it must remove all characters an display only the digits(the phone number). This works as expected on previous android versions, but on Lolipop, it shows the name instead. From the Log I can see that valueNum gets the correct value(the phone number), but the setText somehow changes the valueNum value to name, because these logs get the name. Is something wrong in my code which can cause this, or there is incompability with AutoComplete textView on android L?
UPDATE: This is the log output. Seems that the commands run 2 times. The first one the value is okay, but the second changes.
I/mInput text1:﹕ {Phone=6997777777, Name=Zivol} I/mInput text2:﹕ 6997777777 I/mInput text3:﹕ 6997777777 I/mInput text1:﹕ 699777777 I/mInput text2:﹕ Zivol I/mInput text3:﹕ Zivol