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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:57:02+00:00 2026-05-27T08:57:02+00:00

I’m updating the AutoCompleteTextView dynamically and I’m facing two problems. when item selected there

  • 0

I’m updating the AutoCompleteTextView dynamically and I’m facing two problems.

  • when item selected there is a new onTextChanged event and as you can see in the code below there is a new request to get a new optional items so the onTextChanged event cause the AutoComplete show the drop down again! is there a clean way to solve it?!

  • the results i get from the auto complete are from the previous adapter before I call notifyDataSetChange(), how can i make it happen?!

here is the code:

AutoCompleteTextView acCountry = (AutoCompleteTextView)layout.findViewById(R.id.autoComplete);
final ArrayAdapter<RMAutoComplete.ListItem> countriesAdapter = new ArrayAdapter<RMAutoComplete.ListItem>(this.context,android.R.layout.simple_dropdown_item_1line);
acCountry.setAdapter(countriesAdapter);
acCountry.addTextChangedListener(new TextWatcher() {

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (s.length() > 1)
            {
                new AsyncTask<String, Void, List<RMAutoComplete.ListItem>>(){

                    @Override
                    protected List<ListItem> doInBackground(String... params) {
                        List<ListItem> l = null;
                        try {
                            l = location.getCountryData(params[0]);
                        } catch (Exception e) {
                            Log.e(TAG,"error when getCountryData",e);
                        }
                        return l;
                    }

                    @Override
                    protected void onPostExecute(List<ListItem> countries) {
                        countriesAdapter.clear();
                        if (countries != null)
                            for (ListItem listItem : countries) {
                                countriesAdapter.add(listItem);
                            }
                        countriesAdapter.notifyDataSetChanged();
                    }
                }.execute(s.toString());
            }
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

        public void afterTextChanged(Editable s) {}
    }
);
  • 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-27T08:57:03+00:00Added an answer on May 27, 2026 at 8:57 am

    Well to achive the dynamic adapter what is need to do is to implement custom Filter class and override the performFiltering and publishResults methods.

    In the performFiltering create new instance of FilterResults and initialize his values and count with the new items.. (this method works by default on a new thread!) something like this:

    @Override
        protected FilterResults performFiltering(CharSequence constraint) {
            FilterResults fr = null;
            if (constraint != null)
            {
                List<ListItem> list = getFilterdValues(constraint.toString());
    
                if (list != null)
                {
                    fr = new FilterResults();
                    fr.values = list;
                    fr.count = list.size();
                }
            }
            return fr;
        }
    

    and in the publishResults add the result to the adapter like this:

    @Override
        protected void publishResults(CharSequence constraint,
                FilterResults results) {
            AutoCompleteAdapter.this.clear();
            if (results != null)
            {
                if (results.values != null)
                {
                    List<ListItem> items = (List<ListItem>) results.values;
    
                        for (ListItem listItem : items) {
                            AutoCompleteAdapter.this.add(listItem);
                        }
    
                    if (items.size() > 0)
                    {
                        AutoCompleteAdapter.this.notifyDataSetChanged();
                        return;
                    }
                }
            }
            AutoCompleteAdapter.this.notifyDataSetInvalidated();
        }
    

    also and importent is that you need to custom the adapter and overrirde getFilter with your own new custom Filter class like this:

    public class AutoCompleteAdapter extends ArrayAdapter<RMAutoComplete.ListItem> 
    {
    
    
    private CustomFilter _customFilter = null;
    
    @Override
    public Filter getFilter() {
    
        if (_customFilter == null)
            _customFilter = new CustomFilter();
        return _customFilter;
    }
    
    
    public AutoCompleteAdapter(Context context, int textViewResourceId) {
        super(context, textViewResourceId);
    
    }
    
    }
    

    hope it was helpful for someone..

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
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
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.