0

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) {

    }
}
F4bioo
  • 179
  • 1
  • 5
  • 11
  • I take it your trying to search the listview and then move to the position. Just use google: https://www.google.com/search?client=ubuntu&channel=fs&q=listview+searching&ie=utf-8&oe=utf-8 If that's not it, there's a different answer for each thing you might be trying to do. – CmosBattery Oct 23 '15 at 01:40
  • I think moving ur code from `onTextChange` to `afterTextChanged` should help. – Tejas Oct 23 '15 at 09:49

0 Answers0