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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:05:05+00:00 2026-06-04T18:05:05+00:00

I got this piece of code: public void cap_search(){ EditText search = (EditText) findViewById(R.id.search);

  • 0

I got this piece of code:

public void cap_search(){
        EditText search = (EditText) findViewById(R.id.search);
        String str_search = null;
        adapter = new ItemListAdapter(this, data);
        setListAdapter(adapter);

        str_search = search.getText().toString();
        for (int i = data.size()-1; i >= 0; i--){
            if (!data.get(i).getCaption().contains(str_search)){
                 data.remove(i);
            }
         }
    }

I will explain this code, and what it does in my code:

People get to see a list of caps, they can check all caps which they own.
But because I got a lot of caps, I build in a search function. So when they type: “A” then the list should only show the caps that contains an “A”.
Till this everything works, now the problem.
After they type the: “A” I remove all items that do not contain it. But when the user delete the “A” and type a “B”, then it should check the whole list (also the deleted ones that didn’t start with an “A”) but it doesn’t, because I removed them.

So is it possible to make the items invisible instead of remove them?
Or maybe another way to solve this problem?

I hope it is clear, if not please say it, then I will try to explain it different.

Thanks already, Bigflow

Edit 1:

Tried many answers but I just can’t get it to work properly.
Someone got more ideas?
TextWatcher seems pretty cool, but it is too difficult for me, This is my second project I try to implement it, but also this time I can’t get it to work.
I never used SQL too.

So someone else got any other answers? Or maybe someone that is good with textwatcher, could you make/help me make me one. Examples of textwatchers on the internet are too complicated for me most of the time. I would really appreciate it.

Edit 2:

I am still figuring this option/function out, but what about an use with adapter.getfilter(); ?

  • 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-04T18:05:07+00:00Added an answer on June 4, 2026 at 6:05 pm

    Try using two lists, one with all the results and one with the search result. Display always the second list and if you want to display the whole list just point the second list to the first list.
    Something like:

    private List<Item> displayData = new ArrayList<Item>();
    
    public void cap_search(){
            EditText search = (EditText) findViewById(R.id.search);
            String str_search = null;
    
            str_search = search.getText().toString();
            displayData.clear();
            if (str_search == null || str_search.equals("")) {
                displayData.addAll(data);
            } else {
                for (int i = data.size()-1; i >= 0; i--){
                    if (data.get(i).getCaption().contains(str_search)){
                        displayData.add(data.get(i));
                    }
                }
            }
            adapter = new ItemListAdapter(this, displayData);
            setListAdapter(adapter);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got this piece of code: public class ThreadInteraction { public static void
I've got this piece of code to create new objects in a generic way:
I've got a piece of code like this: class Lekcja { Calendar _date; public
I've got this piece of code to toggle a side panel: $(.example_wrapper_panel_link).click(function() { $(.example_wrapper).addClass('example_wrapper_active');
so i got this piece of code. (currPosX is defined earlier) while (earliestDate <
I've got this piece of code in my jquery validation script: resetForm: function() {
Hallo all. I got this piece of code: <div> <input id=id1 name=radioButton type=radio> <input
I got this piece of Assembly code extracted from some piece of software, but
So I got this little piece of code, don't bother the way it's implemented.
I've got this piece of legacy code which I'm trying to refactor at the

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.