I basically want to add a simple search ability to my list view. Where there is a search bar at the top and the app sorts the searches for me. I would be greatful if anyone could help me. This is a perfect example of what I want: Example. Thanks!
PetActivity.java
public class PetActivity extends Activity {
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.pet_layout);
ListView listView1 = (ListView) findViewById(R.id.listView1);
Pet[] items = {
new Pet("1"),
new Pet(""),
new Pet(""),
new Pet(""),
new Pet(""),
};
ArrayAdapter<Pet> adapter = new ArrayAdapter<Pet>(this,
android.R.layout.simple_list_item_1, items);
listView1.setAdapter(adapter);
listView1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {
if (position == 1)
{
Toast.makeText(getApplicationContext(), "Test", Toast.LENGTH_LONG).show();
}
}
});
}
}
Pet.java
package com.thebuildcast.cubeworldtoolbox;
public class Pet {
private String name;
public Pet(){
super();
}
public Pet(String name){
super();
this.name = name;
}
@Override
public String toString(){
return this.name;
}
}