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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:33:39+00:00 2026-06-13T08:33:39+00:00

I was doing some stuff using autocomplete textview in my application. I’m getting suggestion

  • 0

I was doing some stuff using autocomplete textview in my application. I’m getting suggestion when user types anything. But, I have one query, when user types and taps on the suggested list on the autocomplete textview, then more suggestions comes up. I want to limit the search results when user taps on the list and don’t want to show more options there. How can I overcome this situation.

This is my full class, which I’m working on:

public class WikiSuggestActivity extends Activity {
public String data;
public List<String> suggest;
public AutoCompleteTextView autoComplete;
public ArrayAdapter<String> aAdapter;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    suggest = new ArrayList<String>();
    autoComplete = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
    autoComplete.addTextChangedListener(new TextWatcher() {

        public void afterTextChanged(Editable editable) {
            // TODO Auto-generated method stub

        }

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

        }

        public void onTextChanged(CharSequence s, int start, int before,
                int count) {
            String newText = s.toString();
            new getJson().execute(newText);
        }

    });

}

class getJson extends AsyncTask<String, String, String> {

    @Override
    protected String doInBackground(String... key) {
        String newText = key[0];
        newText = newText.trim();
        newText = newText.replace(" ", "+");
        try {
            HttpClient hClient = new DefaultHttpClient();
            HttpGet hGet = new HttpGet(
                    "http://en.wikipedia.org/w/api.php?action=opensearch&search="
                            + newText + "&limit=8&namespace=0&format=json");
            ResponseHandler<String> rHandler = new BasicResponseHandler();
            data = hClient.execute(hGet, rHandler);
            suggest = new ArrayList<String>();
            JSONArray jArray = new JSONArray(data);
            for (int i = 0; i < jArray.getJSONArray(1).length(); i++) {
                String SuggestKey = jArray.getJSONArray(1).getString(i);
                suggest.add(SuggestKey);
            }

        } catch (Exception e) {
            Log.w("Error", e.getMessage());
        }
        runOnUiThread(new Runnable() {
            public void run() {
                aAdapter = new ArrayAdapter<String>(
                        getApplicationContext(), R.layout.item, suggest);
                autoComplete.setAdapter(aAdapter);
                aAdapter.notifyDataSetChanged();
            }
        });

        return null;
    }

}
}

Any guidance will be appreciated.

  • 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-13T08:33:40+00:00Added an answer on June 13, 2026 at 8:33 am
    public class WikiSuggestActivity extends Activity {
        public String data;
        public List<String> suggest;
        public AutoCompleteTextView autoComplete;
        public ArrayAdapter<String> aAdapter;
        public TextWatcher mTextWatcher = new TextWatcher() {
            public void afterTextChanged(Editable editable) {
                // TODO Auto-generated method stub
            }
    
            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {
                // TODO Auto-generated method stub
            }
    
            public void onTextChanged(CharSequence s, int start, int before,
                    int count) {
                String newText = s.toString();
                new getJson().execute(newText);
            }
        };
        public boolean watch = true;
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            suggest = new ArrayList<String>();
            autoComplete = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
            autoComplete.addTextChangedListener( mTextWatcher );
            autoComplete.setOnItemClickListener( new OnItemClickListener(){
                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                        long arg3) {
                    autoComplete.removeTextChangedListener( mTextWatcher );
                    aAdapter.clear();
                    watch = false;
                }
            });
        }
    
        class getJson extends AsyncTask<String, String, String> {
    
            @Override
            protected String doInBackground(String... key) {
                String newText = key[0];
                newText = newText.trim();
                newText = newText.replace(" ", "+");
                try {
                    HttpClient hClient = new DefaultHttpClient();
                    HttpGet hGet = new HttpGet(
                            "http://en.wikipedia.org/w/api.php?action=opensearch&search="
                                    + newText + "&limit=8&namespace=0&format=json");
                    ResponseHandler<String> rHandler = new BasicResponseHandler();
                    data = hClient.execute(hGet, rHandler);
                    suggest = new ArrayList<String>();
                    JSONArray jArray = new JSONArray(data);
                    for (int i = 0; i < jArray.getJSONArray(1).length(); i++) {
                        String SuggestKey = jArray.getJSONArray(1).getString(i);
                        suggest.add(SuggestKey);
                    }
    
                } catch (Exception e) {
                    Log.w("Error", e.getMessage());
                }
                if( watch )
                    runOnUiThread(new Runnable() {
                        public void run() {
                            aAdapter = new ArrayAdapter<String>(
                                getApplicationContext(), R.layout.item, suggest);
                            autoComplete.setAdapter(aAdapter);
                            aAdapter.notifyDataSetChanged();
                        }
                    });
    
                return null;
            }
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application consisting of many scripts doing some stuff on their own.
I'm doing some Rails stuff with AJAX (not using UJS, but rather rolling my
I have an activity with some views, after doing some stuff I want to
I am doing some server stuff that could potentially fail (not likely) but something
I'm doing some geocoding using the google maps API. The user fill a form
I am doing some stuff in my Javascript function and then I have to
I have been doing some Winsock programming lately. I do not do much stuff
I'm making some stuff using jQuery. Sometimes I have, for example, a bunch of
I'm doing some UIView animation stuff using [UIView beginAnimations:nil context:nil]; // ... Animation configuration
I'm using Jquery mobile and doing some custom stuff. The default collapsible object just

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.