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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:47:26+00:00 2026-06-12T01:47:26+00:00

I have an EditText component that searches a list using a custom adapter. It

  • 0

I have an EditText component that searches a list using a custom adapter. It works fine except that the filtered views remain on screen. If the user deletes all the text in the edit box, I would like the full list to return to the screen.

I’ve tried three approaches:

  1. I put a condition in my adapter’s filter classs. Placeing notifyDataSetChanged(); in FilterResults function, and it crashes the program.

  2. Detecting if the EditTtext box is empty in the Activity, and then calling notifyDataSetChanged();. The condition works because I see System.out.println() prints text to the console. but it has no effect on the listView. Only the filtered text remains on screen.

  3. Placing notifyDataSetChanged(); in OnTextChanged(). This also has no effect on resetting the listview.

How do I get the listview to reset when the EditText Box is empty?

Code from Activity:

// in OnCreate

if (searchBox.toString().equals("")){
                objAdapter.notifyDataSetChanged();


            }


        searchBox.addTextChangedListener(new TextWatcher(){

                @Override
                public void afterTextChanged(Editable arg0) {
                    // Do nothing
                }

                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                    // Do nothing
                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                    objAdapter.getFilter().filter(s);

if (s.toString().equals("")){

                        // objAdapter.notifyDataSetChanged(); fails here 

}

                    }
                }

            });

Code from Adapter.

    public class NewsRowAdapter extends ArrayAdapter<Item> {
    //.... code
    private class ListFilter extends Filter
        {
                @Override
                protected FilterResults performFiltering(CharSequence constraint)
                {   
                    FilterResults results = new FilterResults();
                    String prefix = constraint.toString().toLowerCase();

                    if (prefix == null || prefix.length() == 0)
                    {

                        System.out.println("editText is empty");
                        // notifyDataSetChanged(); no effect

                        ArrayList<Item> list = new ArrayList<Item>(original);
                        results.values = list;
                        results.count = list.size();


                    }
                    else
                    {
                        final ArrayList<Item> list = original;

                        int count = list.size();
                        final ArrayList<Item> nlist = new ArrayList<Item>(count);

                        for (int i=0; i<count; i++)
                        {
                            final Item pkmn = list.get(i);
                            final String value = pkmn.getName().toLowerCase();
                        if (value.startsWith(prefix))
                        {
                            nlist.add(pkmn);
                        }
                    }
                    results.values = nlist;
                    results.count = nlist.size();
                }
                return results;
            }

            @SuppressWarnings("unchecked")
            @Override
            protected void publishResults(CharSequence constraint, FilterResults results) {
                fitems = (ArrayList<Item>)results.values;

                clear();
                int count = fitems.size();
                for (int i=0; i<count; i++)
                {
                    Item pkmn = (Item)fitems.get(i);
                    add(pkmn);
                }

                if (fitems.size() > 0){
                    notifyDataSetChanged();
                } else{
                    notifyDataSetInvalidated();
                }

            }

        }
  • 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-12T01:47:27+00:00Added an answer on June 12, 2026 at 1:47 am

    Instead of searchBox.toString(), use searchBox.getText().toString()

    searchBox.toString() is returning the object’s VM reference — which will never equal nothing

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

Sidebar

Related Questions

If I have an EditText component on my screen that I have specified inputType=decimal
I have an EditText and I want to attach to it a KeyListener that
I have an EditText input that I would like to only allow numbers 1
I have an edittext, and a textwatcher that watches if SPACE arrived or not.
I have made a Custom Component in XML, consisting of a button with an
I have a EditText that I have set to invisible by default. I would
I have inherited EditText class an made my custom class, MyEditText. and want to
Is it possible to have an EditText that allows multilines and doesn't show the
I have list of products which have EditText in TableLayout . I want Keyboard
I have an edittext and I want any character that I type in edittext

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.