Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9036833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:05:47+00:00 2026-06-16T09:05:47+00:00

I had a look at this thread before asking a question here. But that

  • 0

I had a look at this thread before asking a question here. But that thread contains example of simple string array whereas in my case I am using ArrayList<Map<String, String>> so I am bit confused at the moment.

I have a multiple selection listview in my android activity. I am using the listview to display the list of contacts so that the user can select multiple phone numbers at a time. But now I want to add the search functionality for the same purpose. What I want to do is place one EditText at the top and whatever character users types in that EditText, I want the ListView to be filled with filtered data based on users input. I have a CustomAdapter which extends BaseAdapter and a POJO class named Contact which I am using to GET & SET contact details.

MYCUSTOMADAPTER.JAVA

public class MyCustomAdapter extends BaseAdapter {

Context mContext;
private LayoutInflater mInflater;
SparseBooleanArray mSparseBooleanArray;
private ArrayList<Map<String,String>> mAdapData = new ArrayList<Map<String, String>>();

public MyCustomAdapter(Context mContext) {
    mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mSparseBooleanArray = new SparseBooleanArray();
}

public ArrayList<String> getCheckedItems() {
    ArrayList<String> mTempArry = new ArrayList<String>();
    for (int i = 0; i < mAdapData.size(); i++) {
        if (mSparseBooleanArray.get(i)) {
            Map<String, String> map = (Map<String, String>) mAdapData.get(i);
            final String numbr = map.get("Phone").toString();
            mTempArry.add(numbr);
        }
    }
    return mTempArry;
}

public int getCount() {
    return this.mAdapData.size();
}

public void addItem(String paramString1, String paramString2) {
    Map<String, String> NameNumber = new HashMap<String, String>();
    NameNumber.put("Name", paramString1);
    NameNumber.put("Phone", paramString2);
    this.mAdapData.add(NameNumber);
    notifyDataSetChanged();
}

@SuppressWarnings("unchecked")
public Object getItem(int paramInt) {
    return (ArrayList<Map<String, String>>) this.mAdapData.get(paramInt);
}

public long getItemId(int paramInt) {
    return paramInt;
}

public View getView(final int paramInt, View paramView, ViewGroup paramViewGroup) {

    if (paramView == null) {
        paramView = mInflater.inflate(R.layout.multiplecontactview, null);
    }

    TextView txtName = (TextView) paramView.findViewById(R.id.txtContactName);
    TextView txtNumber = (TextView) paramView.findViewById(R.id.txtContactNumber);
    CheckBox mCheckBox = (CheckBox) paramView.findViewById(R.id.checkBox1);
    mCheckBox.setTag(paramInt);
    mCheckBox.setChecked(mSparseBooleanArray.get(paramInt));
    mCheckBox.setOnCheckedChangeListener(mCheckedChangeListener);
    txtName.setTextColor(Color.BLACK);
    txtNumber.setTextColor(Color.BLACK);
    for (int i = 0; i < mAdapData.size(); i++) {
        Map<String, String> map = (Map<String, String>) mAdapData.get(paramInt);
        final String name = map.get("Name").toString();
        final String numbr = map.get("Phone").toString();
        txtName.setText(name);
        txtNumber.setText(numbr);
    }
    return paramView;
}

OnCheckedChangeListener mCheckedChangeListener = new OnCheckedChangeListener() {
    public void onCheckedChanged(CompoundButton buttonView,
            boolean isChecked) {
        mSparseBooleanArray.put((Integer) buttonView.getTag(), isChecked);
    }
};
}

CONTACT CLASS

public class Contact {

int _id;
String _name;
String _phone_number;

public Contact() {

}

public Contact(int id, String name, String _phone_number) {
    this._id = id;
    this._name = name;
    this._phone_number = _phone_number;
}

public Contact(int id) {
    this._id = id;
}

public Contact(String name, String _phone_number) {
    this._name = name;
    this._phone_number = _phone_number;
}

public int getID() {
    return this._id;
}

public void setID(int id) {
    this._id = id;
}

public String getName() {
    return this._name;
}

public void setName(String name) {
    this._name = name;
}

public String getPhoneNumber() {
    return this._phone_number;
}

public void setPhoneNumber(String phone_number) {
    this._phone_number = phone_number;
}

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T09:05:49+00:00Added an answer on June 16, 2026 at 9:05 am

    For you to be able to do that, you need to implement a Textwatcher

    private TextWatcher filterTextWatcher = new TextWatcher() {
    
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
        }
    
        public void onTextChanged(CharSequence s, int start, int before,
                int count) {
    
        }
    
        @Override
        public void afterTextChanged(Editable arg0) {
            /*clear previous contents of list*/
                         adapter.clear();
                        /*add new contents according to the filter*/
                       String filter=arg0.getText().toString();
                       if (filter == null
                                || Pattern
                                        .compile(Pattern.quote(filter),
                                                Pattern.CASE_INSENSITIVE)
                                        .matcher(adapter.getItem(...)).find()
                                || filter.equals("")) {
                            adapter.addItem(...);
                        }
        }
    
    };
    

    Then set that filterTextWatcher to your editext:

    searchEditText.addTextChangedListener(filterTextWatcher);
    

    Hope that helps! 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

for sure this question has been asked before, but I couldn't find any thread
I've had a look around for the answer to this, but I only seem
I've had a look at other questions similar to this one but I couldn't
Apologies if this was already asked but, I have had a look and can't
I had a look at this previous question however this doesn't seem to work
I had a look at this and this but no one sounded particularly sure
I have had look at a few post already here but I am none
I had an exam where I should look at this code and answer the
I had a look through the documentation on the Wiki, but it seems a
I've had a look around SO and Google but can't find a definite and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.