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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:52:43+00:00 2026-06-14T06:52:43+00:00

I tried to have 2 spinners in the same interface, but it is not

  • 0

I tried to have 2 spinners in the same interface, but it is not working. Why ? It displays only one spinner.

One retrieve information from database android:id="@+id/sp11" and the other from string file android:id="@+id/typeMessage_spinner".
Only the one that retrive from array @string file works.
If I delete android:id="@+id/typeMessage_spinner" the one that retrieve from database works.
And in the interface only one spinner is displayed.

like this
http://im13.gulfup.com/W1fV1.png

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world"
        tools:context=".MainActivity" />

      <Spinner
        android:id="@+id/sp11"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:prompt="@string/chooseCourse"
        android:layout_marginTop="20dip"
        android:layout_marginLeft="8dip"
        android:layout_marginRight="8dip"
    />
          <Spinner
        android:id="@+id/typeMessage_spinner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:prompt="@string/chooseCourse"
        android:layout_marginTop="20dip"
        android:layout_marginLeft="8dip"
        android:layout_marginRight="8dip"
    />

</RelativeLayout>

Here is my code in onCreate(). Look at my fist spinner and in onPostExecute() i have the second spinner

  public class MainActivity extends Activity {
        JSONParser jParser = new JSONParser(); // class
        ArrayList<HashMap<String, String>> coursesList;


        private static String url_all_course = "http://10.0.2.2/SmsPhp/view_all_course.php";

        private static final String TAG_SUCCESS = "success";
        private static final String TAG_course = "course";
        private static final String TAG_CourseID = "CourseID";
        private static final String TAG_Name = "Name";
        JSONArray courses = null;
        // Spinner element
         SpinnerAdapter adapter,adapter1;
        Spinner spinner ,spinner1;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            coursesList = new ArrayList<HashMap<String, String>>();

            spinner= (Spinner) findViewById(R.id.typeMessage_spinner);
            spinner1= (Spinner) findViewById(R.id.sp11);
            // Create an ArrayAdapter using the string array and a default spinner layout
            ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( MainActivity .this,
                    R.array.typeMessage_spinner, android.R.layout.simple_spinner_item);
            // Specify the layout to use when the list of choices appears
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            // Apply the adapter to the spinner
            spinner.setAdapter(adapter);
            new LoadAllCourses().execute();

        }

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




            @Override
            protected String doInBackground(String... args) {
                // Building Parameters
                List<NameValuePair> params = new ArrayList<NameValuePair>();
                // getting JSON string from URL
                JSONObject json = jParser.makeHttpRequest(url_all_course, "GET",
                        params);

                // Check your log cat for JSON response
                Log.d("All courses: ", json.toString());

                try {
                    // Checking for SUCCESS TAG
                    int success = json.getInt(TAG_SUCCESS);

                    if (success == 1) {
                        // course found
                        // Getting Array of course
                        courses = json.getJSONArray(TAG_course);

                        // looping through All courses
                        for (int i = 0; i < courses.length(); i++)// course
                                                                    // JSONArray
                        {
                            JSONObject c = courses.getJSONObject(i); // read first

                            // Storing each json item in variable
                            String CourseID = c.getString(TAG_CourseID);
                            String Name = c.getString(TAG_Name);

                            // creating new HashMap
                            HashMap<String, String> map = new HashMap<String, String>();

                            // adding each child node to HashMap key => value
                            map.put(TAG_CourseID, CourseID);
                            map.put(TAG_Name, Name);

                            // adding HashList to ArrayList
                            coursesList.add(map);
                        }
                    } else {


                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                }

                return null;
            }

            /**
             * After completing background task Dismiss the progress dialog
             * **/
            protected void onPostExecute(String file_url) {
                // dismiss the dialog after getting all products


                adapter1 = new CustomAdapter(MainActivity.this,
                        android.R.layout.simple_spinner_item,
                        coursesList);

                 spinner1.setAdapter(adapter1); // Set the custom adapter to the spinner
                    // You can create an anonymous listener to handle the event when is selected an spinner item
                 spinner1.setOnItemSelectedListener(new CustomOnItemSelectedListener() {

                   /*    @Override
                       public void onItemSelected(AdapterView<?> adapterView, View view,
                                int position, long id) {
                            // Here you get the current item (a User object) that is selected by its position
                            ArrayAdapter<HashMap<String, String>> x = (ArrayAdapter<HashMap<String, String>>) adapter.getItem(position);
                            // Here you can do the action you want to...
                            Toast.makeText(MainActivity.this, "ID: "+  x ,
                                Toast.LENGTH_SHORT).show();
                        }*/
                        @Override
                        public void onNothingSelected(AdapterView<?> adapter) {  }
                    });
                }
            }

    }
  • 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-14T06:52:45+00:00Added an answer on June 14, 2026 at 6:52 am

    You have positioned the two spinners on the exact same location.

    Try moving one spinner to some other direction

    <Spinner
        android:id="@+id/sp11"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:prompt="@string/chooseCourse"
        android:layout_marginTop="20dip"
        android:layout_marginLeft="8dip"
        android:layout_marginRight="8dip" />
    <Spinner
        android:id="@+id/typeMessage_spinner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:prompt="@string/chooseCourse"
     add ->  android:layout_below="@+id/sp11"
        android:layout_marginTop="20dip"
        android:layout_marginLeft="8dip"
        android:layout_marginRight="8dip" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried searching over the internet about this problem but not able to
I have tried many permutations but they all don't seems to work well. Am
I have tried to upload image using FileTransfer.upload in phonegap api.But I am getting
i have tried to play music via spinner and i have done it. Whenever
I have a Main-Activity which displays several spinners. With a Toggle-Button in the Main-Activity
I have a custom spinner that uses two custom views, one for the drop
I have a spinner with a custom adapter displaying objects from a database. When
I have created a spinner with 3 options: Beginner, Advanced and Pro. When one
I have a spinner which is populated with Category objects that are retrieved from
I have two AsyncTask that are not working. There must be something in common

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.