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 9050987
In Process

The Archive Base Latest Questions

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

I have ListView with custom adapter extends ArrayAdapter. Each item is object: public class

  • 0

I have ListView with custom adapter extends ArrayAdapter. Each item is object:

public class ListItemObject {

    public String messageText;
    public long messageTime;
    public long fromId;
    public long toId;

}

I want to add checkable item in menu for filtering switching. So when this item unchecked I will show all items, and when this item checked ListView must contain only filtered items with this condition:

if(fromId==myId || toId==myId) {
//show item
} else {
//don't show item
}

I see two ways to implement this:

  1. Make my own filter extends Filter. Then call adapter.getFilter().filter(string_with_fromId_and_toId_in_JSON). I see one problem here: to all appearance adapter can contain only one filter. And if I want to add another filter in future, I can’t do it.

  2. Save all items outside the adapter, clear it and fill again with filtered data. That is not convenient method for me, but I can do it.

How to better to implement this?

  • 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-16T12:47:34+00:00Added an answer on June 16, 2026 at 12:47 pm

    I have used both. I created a flag like FILTER_BY_CUSTOM_COLLECTION and send it to filter function as constraint parameter. If constraint is equal to my flag I do my custom filter else I use that constraint as a real text constraint:

    MyFilter filter = (MyFilter) adapterDocumentDetails.getFilter();
    
    filter.itemsForFilterResult = anyCollection
    
    filter.filter(MyFilter.FILTER_BY_CUSTOM_COLLECTION,
                new FilterListener() {
                    @Override
                    public void onFilterComplete(int count) {
    
                    }
                });
    

    in my filter:

       public final static String FILTER_BY_CUSTOM_COLLECTION = "@@FILTER_BY_CUSTOM_COLLECTION@@";
        @Override
        protected FilterResults performFiltering(CharSequence constraint) {
    
        if (constraint.toString().compareTo(
                                        FILTER_BY_CUSTOM_COLLECTION) == 0
                                        && itemsForFilterResult != null) 
        {
           filteredCollection = itemsForFilterResult;
        }
        else
        {
           for (int i = 0; i < allItems.size(); i++) 
           {
             ListItemObject  item= allItems.get(i);
             if(item.messageText.contains(constraint))
             {
                filteredCollection.add(item);
             }
           }    
        }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a listview with a custom array adapter: public class SmsMessageAdapter extends ArrayAdapter<ContactMessage>
I have a ListView with a custom Adapter that extends ArrayAdapter. It's a ArrayAdapter
I have a custom ArrayAdapter populating a ListView . Here it is: public class
I have a custom ArrayAdapter I use to manage my ListView: public class FilesAdapter
I created a custom ListView. Each item in the list have one imageView and
I have made a custom adapter class here is the code public class CustomArrayAdapterForReceipts
I want to have a listview with a custom adatper, extends ArrayAdapter, where Type
I have a ListView with custom Adapter . To be honest, I have many
I have a ListView with custom Adapter . I have to add at position
I have a ListView with a custom adapter, and an animation in getView() for

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.