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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:13:52+00:00 2026-05-28T14:13:52+00:00

How do i have an AutoComplete selection based on alphabetic instead of fixed switch

  • 0

How do i have an AutoComplete selection based on alphabetic instead of fixed switch cases? The situation is, everything working except when i input keyword with “B” showing Badrul as first suggestion but when clicked it will still refer to the first switch cases which is opening up Adidas.class instead of Badrul.class

Please help, i am new in this. Is AutoComplete suitable for my requirement?

public class Search extends Activity
{
    public void onCreate(Bundle savedInstanceSate)
    {
        super.onCreate(savedInstanceSate);
        setContentView(R.layout.searchshop);

        AutoCompleteTextView autoComplete = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, shops);
        autoComplete.setAdapter(adapter); 
        autoComplete.setThreshold(1);
        autoComplete.setOnItemClickListener(new OnItemClickListener()
        {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) 
        {
            switch(position)
            {
            case 0:
                startActivity(new Intent(Search.this, Adidas.class));
                break;
            case 1:
                startActivity(new Intent(Search.this, Affin.class));
                break;
            case 2:
                startActivity(new Intent(Search.this, AlamArt.class));
                break;
            case 3:
                startActivity(new Intent(Search.this, Badrul.class));
                break;
            }
        }
        });     
    }
    static final String[] shops = new String[]
            {
                "Adidas", "Affin Bank", "Alam Art Gallery", "Badrul"
            };
}
  • 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-28T14:13:53+00:00Added an answer on May 28, 2026 at 2:13 pm

    This is obvious behavior as you are referring to the position of the suggestion at current time,so it would be differed according to what user types in. For achieving what you want,You need to change your code according to this:

    public class Search extends Activity
    {
        public void onCreate(Bundle savedInstanceSate)
        {
            super.onCreate(savedInstanceSate);
            setContentView(R.layout.searchshop);
    
            final AutoCompleteTextView autoComplete = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, shops);
            autoComplete.setAdapter(adapter); 
            autoComplete.setThreshold(1);
            autoComplete.setOnItemClickListener(new OnItemClickListener(){
    
                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
                    int index=999;
                    for(int i=0;i<shops.length;i++)
                    {
                        if(autoComplete.getText().toString().trim().equals(shops[i]))
                        {
                             index=i;
                             break;
                        }               
                    }
                    switch(index)
                    {
                        case 0:
                             startActivity(new Intent(Search.this, Adidas.class));
                             break;
                        case 1:
                             startActivity(new Intent(Search.this, Affin.class));
                             break;
                        case 2:
                             startActivity(new Intent(Search.this, AlamArt.class));
                             break;
                        case 3:
                             startActivity(new Intent(Search.this, Badrul.class));
                             break;
                        default:
                             Toast.makeText(Search.this, "Invalid Selection", Toast.LENGTH_SHORT).show();
                   }
               }
           });     
        }
        static final String[] shops = new String[]
        {
              "Adidas", "Affin Bank", "Alam Art Gallery", "Badrul"
        };
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery autocomplete field working fine followed by a date input field.
I have a problem with populating an autocomplete list based on a previous input.
I have a jQuery Autocomplete field on an ASP.Net Webform and everything has been
I'm using Jorn Zaefferer's Autocomplete query plugin, http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/ Everything seems to be working as
I have used the jquery-ui to autocomplete an input box and set a hidden
I have problem with Autocomplete, it works well in all browsers except for IE.
I have a jQuery UI Dialog Box that contains a jQuery UI Autocomplete input
I have the following code - http://jsfiddle.net/vcvsb/1/ - per $(document).ready(function(e) { $(input#autocomplete).autocomplete({ source: [c++,
I have a form which populates 3 fields based on the selection from an
So, I have an autocomplete dropdown with a list of townships. Initially I 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.