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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:35:11+00:00 2026-05-30T00:35:11+00:00

I’m using ListView to show search results. I have a Coustomized arrayListAdapter which returns

  • 0

I’m using ListView to show search results. I have a Coustomized arrayListAdapter which returns a list of Objects. This is working fine. My listView is showing just a TextView nothing else.

But I want to clear the List when I again go to the search page. I have tried

@Override
protected void onResume()
{
    mListAdapter.clear();
    mListAdapter.notifyDataSetChanged();
    super.onResume();
}

And the SearchListAdapter

public class SearchListAdapter extends ArrayAdapter<Chapter>
{
public Context context;
private static String searchText = null;

public SearchListAdapter(Context context)
{
    super(context, R.layout.favorite_tab_list_view_row);
    this.context = context;
}

@Override
public void clear()
{
    for (int i = 0; i < getCount(); i++)
        getSearchChapters().remove(i);
    notifyDataSetChanged();
    super.clear();
}

private ArrayList<Chapter> getSearchChapters()
{
    ArrayList<Chapter> chapter = new ArrayList<Chapter>();
    if (searchText != null)
        for (int i = 0; i < DataStore.getHierarchicalChapters()
                .getSubChapters().size(); i++)
        {
            String str = DataStore.getHierarchicalChapters()
                    .getSubChapters().get(i).getChapterContent()
                    .toLowerCase();
            Pattern pat = Pattern.compile(searchText.toLowerCase());
            Matcher mat = pat.matcher(str);

            while (mat.find())
            {mat.start()); //
                chapter.add(DataStore.getHierarchicalChapters()
                        .getSubChapters().get(i)); // the
                break;
                // occurrance
            }
            if (DataStore.getHierarchicalChapters().getSubChapters().get(i)
                    .hasSubchapters())
            {
                for (int j = 0; j < DataStore.getHierarchicalChapters()
                        .getSubChapters().get(i).getSubChapters().size(); j++)
                {
                    str = DataStore.getHierarchicalChapters()
                            .getSubChapters().get(i).getSubChapters()
                            .get(j).getChapterContent();
                    mat = pat.matcher(str);
                    while (mat.find())
                    {
                        chapter.add(DataStore.getHierarchicalChapters()
                                .getSubChapters().get(i).getSubChapters()
                                .get(j));
                        break;
                    }
                }
            }

        }
    return chapter;
}

@Override
public int getCount()
{
    return getSearchChapters().size();
}

@Override
public Chapter getItem(int position)
{

    return getSearchChapters().get(position);

}

@Override
public View getView(int position, View convertView, ViewGroup parent)
{

    View row = convertView;

    if (row == null)
    {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        row = inflater.inflate(R.layout.favorite_tab_list_view_row, parent,
                false);
        ViewHolder viewHolder = new ViewHolder();
        viewHolder.chapterName = (TextView) row
                .findViewById(R.id.favoriteChapterTextViewId);

        row.setTag(viewHolder);
    }
    ViewHolder viewHolder = (ViewHolder) row.getTag();

    viewHolder.chapterName.setText(getSearchChapters().get(position)
            .getTitle());

    return row;
}

static class ViewHolder
{
    public TextView chapterName;
}

public static void setSearchText(String searchText)
{
    SearchListAdapter.searchText = searchText;
}
}

My question is, How can I clear the list ?

Thank You.

  • 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-05-30T00:35:13+00:00Added an answer on May 30, 2026 at 12:35 am

    I think you have to override the method clear() for your custom ArrayAdapter and manually empty the list of objects on which your adapter is based(and don’t forget to call notifyDataSetChanged()). This is what the default ArrayAdapter is doing.

    EDIT :

    Your code will never work now because your custom adapter gets its data from calling the method private ArrayList<Chapter> getSearchChapters() which rebuilds the adapter’s data every time the method is called(for example every time the adapter calls getView() it will rebuild the data). My advice is to make a private field in your adapter :

    ArrayList<Chapter> data;
    

    and then in your adapter’s constructor initialize it by calling the method getSearchChapters() :

    data = getSearchChapters();
    

    Then you can override the method clear():

        @Override
        public void clear() {
            data.clear();
            notifyDataSetChanged();
            super.clear();
        }
    

    Also you can’t call clear from onResume() because your list will never get populated with data(the adapter will be empty). I didn’t understand when you want to clear the list so i can’t tell you when to call the adapter.clear(). You can make a test with a button that calls clear() to see if this clears the adapter.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.