ArrayAdapter already has filter functionality, and ListView can accept search text, so you don't need to re-invent the wheel.
Example:
Have a class hold the data, whenever data has multiple objects:
Public class FullName {
public final String firstName;
public final String lastName;
public Fullname(String fn, String ln){
this.firstName = fn;
this.lastName = ln;
}
@Override
public String toString(){
// this is what ArrayAdapter uses for display and search
return firstName + " " + lastName;
}
}
Inside Activity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ListView nameList = new ListView(this);
setContentView(nameList);
ArrayAdapter<FullName> nameAdapter = new ArrayAdapter<FullName>(this,android.R.layout.simple_list_item_1);
nameAdapter.add( new FullName("John","Doe") );
nameAdapter.add( new FullName("Bob","Carson") );
nameAdapter.add( new FullName("Kyle","Connor") );
nameList.setAdapter(nameAdapter);
//bring up the keyboard, start typing on a ListView and it will filter out matching results
nameList.setTextFilterEnabled(true);
}
In case you really want to search using an EditText:
nameAdapter.getFilter.filter(myEditText.getText());
clear filter:
nameAdapter.getFilter.filter(null);