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

  • Home
  • SEARCH
  • 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 7638457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:10:56+00:00 2026-05-31T08:10:56+00:00

I’ve my main custom listactivity class that have a instance object of my custom

  • 0

I’ve my main custom listactivity class that have a instance object of my custom extended class from ArrayAdapter. My Textwatcher is picking up character and searching fine over the adapter but when I press “Backspace” or “DEL” button to remove my character, my listview gets empty instead of showing all the records..

This is my activity.

adapter = new ProjectArrayAdapter(this, titles, statuses, ids, starteds);

                eTprojectsearch = (EditText) findViewById(R.id.txtprojectsearch);
                eTprojectsearch.addTextChangedListener(Listener__SearchProject);

                eTprojectsearch.setOnEditorActionListener(new OnEditorActionListener() {

                    @Override
                    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                        if(actionId == KeyEvent.KEYCODE_DEL) {
                            if(eTprojectsearch.getText().toString().trim().equals("")) {
                                setListAdapter(adapter);
                            }
                        }
                        return false;
                    }
                });              
                setListAdapter(adapter);

My function of Listener__SearchProject is..

private TextWatcher Listener__SearchProject = new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

            adapter.getFilter().filter(s);
            adapter.notifyDataSetChanged();
            //notifyAll();

            /*
             * if(s.length() == -1) {
                setListAdapter(adapter);
            } else {
                adapter.getFilter().filter(s,new Filter.FilterListener() {

                    public void onFilterComplete(int count) {
                        Log.i("ADAPTER:COMPLETE COUNT",String.valueOf(count));
                        adapter.setNotifyOnChange(true);
                    }
                });
            }
             */
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    };

And here is my Adapter complete class with my Viewholder and etc.

public class ProjectArrayAdapter extends ArrayAdapter<String> implements Filterable {

    private final Activity context;
    private final List<String> titles;
    private final List<String> statuses;
    private final List<String> ids;
    private final List<String> starteds;
    ProjectFilter filter;
    public final Object mLock = new Object();

    ArrayList<String> items;
    ArrayList<String> filteredItems;

    static class PViewHolder {
        public TextView title;
        public TextView status;
        public TextView id;
        public TextView started;
    }

    public ProjectArrayAdapter(Activity context, List<String> titles,List<String> statuses,List<String> ids,List<String> starteds) {
        super(context, R.layout.projectlist, titles);
        this.context    = context;
        this.titles     = titles;
        this.statuses   = statuses;
        this.ids        = ids;
        this.starteds   = starteds;
        this.items = (ArrayList<String>)titles;
        this.filteredItems = this.items;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View rowView = convertView;
        if (rowView == null) {
            LayoutInflater inflater = context.getLayoutInflater();
            rowView = inflater.inflate(R.layout.projectlist, null);
            PViewHolder viewHolder = new PViewHolder();
            viewHolder.title        = (TextView) rowView.findViewById(R.id.projecttitle);
            viewHolder.status       = (TextView) rowView.findViewById(R.id.projectstatus);
            viewHolder.id           = (TextView) rowView.findViewById(R.id.projectid); 
            viewHolder.started      = (TextView) rowView.findViewById(R.id.projectstarted);
            rowView.setTag(viewHolder);
        }

        PViewHolder holder = (PViewHolder) rowView.getTag();
        String title        = titles.get(position);
        String status       = statuses.get(position);
        String id           = ids.get(position);
        String started      = starteds.get(position);
        holder.title.setText((title.length() > 17 ? title.substring(0, 17)+"..." : title));
        holder.status.setText(status);
        holder.id.setText(id);
        holder.started.setText(started);
        return rowView;

    }

    public Filter getFilter() {
        if (filter == null){
            filter = new ProjectFilter();
        }
        return filter;
    }

    private class ProjectFilter extends Filter {         

        @SuppressWarnings({ "rawtypes", "unchecked" })
        @Override
        protected FilterResults performFiltering(CharSequence prefix) {            
            FilterResults results = new FilterResults();

            if (prefix == null || prefix.length() == 0) {
                synchronized (mLock) {
                    results.values = items;
                    results.count = items.size();
                }
            } else {
                synchronized(mLock) {
                    String prefixString = prefix.toString().toLowerCase();
                    final ArrayList filteredItems = new ArrayList();
                    final ArrayList localItems = new ArrayList();
                    localItems.addAll(items);
                    final int count = localItems.size();
                    for (int i = 0; i < count; i++) {
                        final String cString = String.valueOf(localItems.get(i));
                        if (cString.contains(prefixString.toLowerCase())) {
                            filteredItems.add(cString);
                        }                        
                    }

                    results.values = filteredItems;
                    results.count = filteredItems.size();
                }//end synchronized
            }

            return results;
        }

        protected void publishResults(CharSequence prefix, FilterResults results) {
            synchronized(mLock) {
                @SuppressWarnings("unchecked")
                final ArrayList<String> localItems = (ArrayList<String>) results.values;
                notifyDataSetChanged();
                clear();
                for (Iterator<String> iterator = localItems.iterator(); iterator
                        .hasNext();) {
                    String gi = (String) iterator.next();
                    add(gi);
                }
            }//end synchronized
        }
    }
}

Please point me out where I’m mistaken..

  • 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-31T08:10:58+00:00Added an answer on May 31, 2026 at 8:10 am

    ArrayList<String> items and ArrayList<String> filteredItems in ProjectArrayAdapter and List<T> mObjects; in ArrayAdapter refer to the same ArrayList instance. (Call clear() method of ArrayAdapter, then check items.size() it must be zero.)

    1. Remove this line adapter.notifyDataSetChanged(); from onTextChanged

    2. Replace this.items = (ArrayList<String>)titles; (in constructor) with this.items = new ArrayList<String>(titles);

    3. publishResults() method should look like…

          synchronized(mLock) {
              final ArrayList<String> localItems = (ArrayList<String>) results.values;
              clear();
              for (String gi : localItems) {
                  add(gi);
              }
              notifyDataSetChanged();
          }
      

    Are you sure you need ArrayList<String> filteredItems; in ProjectArrayAdapter? Remove it unless it is necessary.

    • 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
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites 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.