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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:48:29+00:00 2026-06-06T18:48:29+00:00

how can i make a drop down list on android ?i google it and

  • 0

how can i make a drop down list on android ?i google it and found many results but from the official android website and it is forbidden

i found something called List View

how can i use it (if it was the right component i have to build)

i will add these lines because stackoverflow doesn’t allow me to submit the question

<tag status="remove" because="can't add question"/>
int i=0; while(i=1;i<4;i++)
system.out.println("sorry");
<?Php
$word="sorry";
echo $word;
?>

after adding code

public class getCellsFromServer extends
            AsyncTask<String, Integer, String[]> {
        ProgressDialog dialog;

        @Override
        protected void onCancelled() {
            super.onCancelled();
        }

        @Override
        protected void onPostExecute(String[] results) {
            super.onPostExecute(results);
            final MyData items [] = new MyData[results.length];
            for(int i=0;i<results.length;i++){
                items[i]= new MyData(results[i],results[i]);
            }
            ArrayAdapter<MyData> adapter = new ArrayAdapter<MyData>(this,
                    android.R.layout.simple_spinner_item, items);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinner.setAdapter(adapter);

        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            dialog = new ProgressDialog(AnswerQuestion.this);
            dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            dialog.setMax(100);
            dialog.show();
        }

        @Override
        protected void onProgressUpdate(Integer... values) {
            super.onProgressUpdate(values);
            dialog.incrementProgressBy(values[0]);
        }

        @Override
        protected String[] doInBackground(String... params) {
            for (int i = 0; i < 20; i++) {
                publishProgress(5);
                try {
                    Thread.sleep(88);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            dialog.dismiss();
            URI website;
            try {
                HttpClient client = new DefaultHttpClient();
                website = new URI(
                        "http://10.0.2.2:8080/LocalizedBasedComptitionServer/GetCells");
                HttpPost request = new HttpPost();
                request.setURI(website);
                HttpResponse response = client.execute(request);
                ObjectInputStream in = new ObjectInputStream(response.getEntity().getContent()); //Android
                String commingArray ="";
                int c=0;
                c=in.read();
                while(c!=-1){
                    commingArray+=(char)c;
                    c=in.read();
                }
                String[] ar = commingArray.split(",");
                return ar;
            } catch (URISyntaxException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }
        class MyData {
            public MyData(String spinnerText, String value) {
                this.spinnerText = spinnerText;
                this.value = value;
            }

            public String getSpinnerText() {
                return spinnerText;
            }

            public String getValue() {
                return value;
            }

            public String toString() {
                return spinnerText;
            }

            String spinnerText;
            String value;
        }

    }
  • 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-06T18:48:32+00:00Added an answer on June 6, 2026 at 6:48 pm

    I have an example where I used Constants, hope this will help you

    Constants

    public static final CharSequence[] DAYS_OPTIONS  = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
    

    Setup of Spinner

    ArrayAdapter<String> adapter = new ArrayAdapter<String> (this, android.R.layout.simple_spinner_item, DAYS_OPTIONS);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinner.setAdapter(adapter);
    

    Hope this will clear your question.


    More explained example

    Activity code

    public class SpinnerTest extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            Spinner s = (Spinner) findViewById(R.id.spinner);
            //Prepar adapter 
            //HERE YOU CAN ADD ITEMS WHICH COMES FROM SERVER.
            final MyData items[] = new MyData[3];
            items[0] = new MyData("key1", "value1");
            items[1] = new MyData("key2", "value2");
            items[2] = new MyData("key3", "value3");
            ArrayAdapter<MyData> adapter = new ArrayAdapter<MyData>(this,
                    android.R.layout.simple_spinner_item, items);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            s.setAdapter(adapter);
            s.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                public void onItemSelected(AdapterView<?> parent, View view,
                        int position, long id) {
                    MyData d = items[position];
    
                    //Get selected value of key 
                    String value = d.getValue();
                    String key = d.getSpinnerText();
                }
    
                public void onNothingSelected(AdapterView<?> parent) {
                }
            });
        }
    
        class MyData {
            public MyData(String spinnerText, String value) {
                this.spinnerText = spinnerText;
                this.value = value;
            }
    
            public String getSpinnerText() {
                return spinnerText;
            }
    
            public String getValue() {
                return value;
            }
    
            public String toString() {
                return spinnerText;
            }
    
            String spinnerText;
            String value;
        }
    }
    

    *layout as *

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    
        <Spinner android:id="@+id/spinner"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:drawSelectorOnTop="true"
            android:prompt="@string/item_prompt"
        />
    
    
    </LinearLayout>
    

    And here is SO how to add items to the spinner dynamically in android?

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

Sidebar

Related Questions

I am trying to create a drop down list. I have it working but
Is there any way to make the auto-suggest drop down list appear for locally
I have a drop down list, and I added some items in it as
I am trying to populate a drop down list when a specific list item
I'm trying to use Dashcode to create a drop-down list for an iPhone Web
I have a drop-down list box and two text fields of id values namely
Can a substring have mutiple arguments? I am pulling a substring from a drop
I have two drop-down lists populated from an array of same dates stored in
I'm trying to create a Django app where the user can make a list
I have a drop down list's select tag that looks like this: <select name=MyName

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.