I have a problem with my TextWatcher. whenever I search for an item, I get return "0" in a ArrayAdapter. but if I do not use the filter and just click on any item on the list, I get the correct position.
I need to get the correct position after using TextWatcher to implement other functions.
Can anyone help me? because I'm still learning how to program. thank you.
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Name name = adpName.getItem(position);
Intent it = new Intent(this, ActAddName.class);
it.putExtra(PAR_NAME, name);
startActivityForResult(it, 0);
Toast.makeText(getBaseContext(), "Position: " + position, Toast.LENGTH_LONG).show();
}
private class FilterName implements TextWatcher {
private ArrayAdapter<Name> arrayAdapter;
private FilterName(ArrayAdapter<Name> arrayAdapter) {
this.arrayAdapter = arrayAdapter;
}
public void setArrayAdapter(ArrayAdapter<Name> arrayAdapter) {
this.arrayAdapter = arrayAdapter;
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
arrayAdapter.getFilter().filter(s);
}
@Override
public void afterTextChanged(Editable s) {
}
}