Organizational Research By

Surprising Reserch Topic

filtering listview with custom object adapter

filtering listview with custom object adapter  using -'android,listview,filter,adapter'

I'm trying to implement filtering of a ListView which is uses a custom object adapter, but I can't find any useful samples. The included code is very simplified, so no- keep in mind I can't use an regular ArrayAdapter.
I have a EditText above the ListView, and when the user enters text in the EditText widget I would like to filter the ListView by the text written in the EditText.
Any suggestions would be much appreciated!

Here is the snippet from the activity class:

public class management_objects extends Activity {

private static List<User> UserList;
private EfficientAdapter adapter = null;
private ListView objectListView = null;
private EditText SearchText = null;

private static class EfficientAdapter extends BaseAdapter implements Filterable{
    private LayoutInflater mInflater;   

    public EfficientAdapter(Context context) {
        mInflater = LayoutInflater.from(context);

    public int getCount() {
        return UserList.size();

    public Object getItem(int position) {
        return position;

    public long getItemId(int position) {
        return position;

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.imagelayout_2lines, null);
            holder = new ViewHolder();
            holder.text = (TextView) convertView.findViewById(;
            holder.subtext = (TextView) convertView.findViewById(;
            holder.icon = (ImageView) convertView.findViewById(;
        else {
            holder = (ViewHolder) convertView.getTag();


        return convertView;

    static class ViewHolder {
        TextView text;
        TextView subtext;
        ImageView icon;

    public Filter getFilter() {
        return null;

public void onCreate(Bundle savedInstanceState) {
    Bundle extras = getIntent().getExtras();

    SearchText = (EditText) findViewById(;    

    objectListView = (ListView) findViewById(;
    adapter = new EfficientAdapter(this);
    ComputerName = extras.getString("COMPUTER_NAME");

    //Get User list from webservice

Here is The User class:

 public class User {
  private int UserId;
  private String FirstName;
  private String LastName;

    public int getUserId() {
        return UserId;
    public void setUserId(int UserId) {
        this.UserId = UserId;
    public String getFirstName() {
        return FirstName;
    public void setFirstName(String FirstName) {
        this.FirstName = FirstName;
    public String getLastName() {
        return LastName;
    public void setLastName(String LastName) {
        this.LastName = LastName;


asked Sep 15, 2015 by EleanorePeth
0 votes

Related Hot Questions

2 Answers

0 votes
answered Sep 15, 2015 by RubinLeafar
0 votes
answered Sep 15, 2015 by LindseyCMWlm