I'm using array adapter to implement a search view to search for hard coded elements
my code as follows
public class MainActivity extends AppCompatActivity {
ListView list;
ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.toolbar);
list = (ListView) findViewById(R.id.list_view);
EditText edittext = (EditText) findViewById(R.id.editText);
edittext.addTextChangedListener(textWatcher);
adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.row_item, COUNTRIES);
}
TextWatcher textWatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.toString().equals(""))
list.setAdapter(null);
else {
adapter.getFilter().filter(s.toString());
adapter.notifyDataSetChanged();
list.setAdapter(adapter);
// adapter.clear();
Log.v("HEY", adapter.getCount() + "");
}
}
@Override
public void afterTextChanged(Editable s) {
}
};
private static final String[] COUNTRIES = new String[]{
"FAAAFA", "France", "FOO"};
}
When i type F in the search for example, the count is printed 0 instead of 3 then when i apply any other query the count is 3 (ie it prints the count of previous query to current one)