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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:22:26+00:00 2026-05-17T20:22:26+00:00

Can anyone please tell me how to add multiple spinners with only one onItemSelected().

  • 0

Can anyone please tell me how to add multiple spinners with only one onItemSelected().
Right now i am doing something like this:
Spinner s[] = new Spinner[5];
I am using this for displaying hierarchy in spinners.

For index = 0; it works fine. But problem arises with next index as there is only one onItemSelected().

What can you suggest on this?

Note: I am coding to have spinners created dynamically and filled with corresponding cursor. Cursor is not an issue so far.

Thanks!

  • 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-17T20:22:27+00:00Added an answer on May 17, 2026 at 8:22 pm
    Public class HomePage extends Activity implements OnClickListener, OnItemSelectedListener{
    
    int orientation;
    DataBaseHelper myDbHelper;
    Cursor c3, c2;
    SimpleCursorAdapter adapterData;
    int index = 0;
    Spinner s[] = new Spinner[5];
    TableRow row;
    
    @SuppressWarnings("static-access")
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        myDbHelper = new DataBaseHelper(this);
    
        //-----------Customized Adapter for Specialties----Database binded//
        String[] columns2 =  {myDbHelper.KEY_ID, myDbHelper.KEY_TITLE};
        String table2 = myDbHelper.DB_TABLE_NAME;
        c2 = myDbHelper.getHandle().query(table2, columns2, "type = 'SuperTab'", null, myDbHelper.KEY_TITLE, null, myDbHelper.KEY_TITLE);
        startManagingCursor(c2);
        String[] from = new String[]{myDbHelper.KEY_TITLE};
        int[] to = new int[]{android.R.id.text1};
        adapterData =
              new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, c2, from, to );
        adapterData.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
    
    
        //-----------Customized Adapter for Location-----Database binded--//
            String[] columns3 =  {myDbHelper.KEY_ID, myDbHelper.KEY_LOCATION};
            String table3 = myDbHelper.DB_TABLE_NAME_LOCATION;
            c3 = myDbHelper.getHandle().query(table3, columns3, null, null, myDbHelper.KEY_LOCATION, null, null);
            startManagingCursor(c3);
            String[] from3 = new String[]{myDbHelper.KEY_LOCATION};
            int[] to3 = new int[]{android.R.id.text1};
            SimpleCursorAdapter adapterData3 =
                  new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, c3, from3, to3 );
                adapterData3.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
        //--------------------------------------------------------------//
    
        Spinner spinner = (Spinner) findViewById(R.id.spinner);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
                this, R.array.specialty_array, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    
        spinner.setAdapter(adapterData);      
    
        Spinner spinner2 = (Spinner) findViewById(R.id.spinner2);
        adapter = ArrayAdapter.createFromResource(
                this, R.array.office_array, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner2.setAdapter(adapterData3);
    
        Button search = (Button)this.findViewById(R.id.Search);
        search.setOnClickListener(this);
    
        Button searchNearMe = (Button)this.findViewById(R.id.Near_Me);
        searchNearMe.setOnClickListener(this);
    
        spinner.setOnItemSelectedListener(this);  
    
        orientation = getResources().getConfiguration().orientation;
    
        s[index] =  new Spinner(this);
    // s[index].setOnItemSelectedListener(this);
        row = new TableRow(this);
    }
    
    @SuppressWarnings("static-access")
    
    public void onItemSelected(AdapterView<?> parent, View view, int pos,
            long id) {
        TextView tv = (TextView)this.findViewById(R.id.spinnerText2);   
    
    
        Log.w("ID: ", "index=" + adapterData.getItemId(pos) + " " + c2.getCount() + " " + id + " callee " + view);
    
        String sql = "sql" +                     id                                                                 ;
    
        c2 = myDbHelper.getHandle().rawQuery(sql, null);
        Log.w("ID Adapter: ", "index=" + adapterData.getItemId(pos) + " " + c2.getCount());
    
        int thisOrientation = getResources().getConfiguration().orientation;
    
        if (thisOrientation != orientation) {
            return;
        }       
    
        //--------sets hierarchy spinner to corresponding database-----//
        String[] from = new String[]{myDbHelper.KEY_TITLE};
        int[] to = new int[]{android.R.id.text1};
        SimpleCursorAdapter adapterDataNew =
              new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, c2, from, to );
        adapterDataNew.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
        Log.w("Adapter Data New", "index=" + adapterDataNew.getItemId(pos) + " " + adapterDataNew.getCount());
        //------------------------------------------------------------//
    
        //-----------------Table Row for Landscape mode---------------//
    
        TableLayout tl = (TableLayout)this.findViewById (R.id.Table);
        TableLayout.LayoutParams tlp = new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); 
        tlp.weight = 1;
        tlp.setMargins(20, 15, 20, 0);
        row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));       
    
        //------------------------------------------------------------//
    
        //------------------find Relative Layout by ID----------------//
        RelativeLayout relative = (RelativeLayout)this.findViewById(R.id.rlay);
        RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(
                android.view.ViewGroup.LayoutParams.FILL_PARENT, 
                android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
        p.addRule(RelativeLayout.BELOW, R.id.spinner);
        p.setMargins(15, 5, 15, 5);
        //------------------------------------------------------------//
    
        if (orientation != getResources().getConfiguration().ORIENTATION_LANDSCAPE) {
            if (c2.getCount() > 0) {                
                relative.removeView(s[index]);
                relative.addView(s[index], android.view.ViewGroup.LayoutParams.MATCH_PARENT, 
                        android.view.ViewGroup.LayoutParams.MATCH_PARENT);
                s[index].setVisibility(view.VISIBLE);
                s[index].setPromptId(R.string.Sub);
                s[index].setAdapter(adapterDataNew);
                s[index].setLayoutParams(p);
                tv.setPadding(10, 50, 10, 0);
    
                Log.w("Index value ", " " + index);
    
            }
            else {
                s[index].setVisibility(view.GONE);
                relative.removeView(s[index]);
                tv.setPadding(0, 0, 0, 0);
            }
        }
        else {
                if (c2.getCount() > 0) {
                    tl.removeView(row); 
                    row.removeView(s[index]);                   
                    Log.w("Row Parent " + row.getParent()," tl child " + tl.getChildCount());
                    tl.addView(row, index + 4 , tlp);
                    row.addView(s[index]);
                    Log.w("Row Parent After Add" + row.getParent()," tl child After Add" + tl.getChildCount());
                    row.setVisibility(view.VISIBLE);                    
                    s[index].setVisibility(view.VISIBLE);
                    s[index].setPromptId(R.string.Sub);
                    s[index].setAdapter(adapterDataNew);
    
                    Log.w("ID: Landscape mode", "index=" + adapterDataNew.getItemId(pos) + " " + adapterDataNew.getCount());
                }   
                else {
                    s[index].setVisibility(view.GONE);
                    row.setVisibility(view.GONE);
                    row.removeView(s[index]);
                    tl.removeView(row);                 
                }
    
        }
    
    }
    
    
    public void onNothingSelected(AdapterView<?> arg0) {        
    
    }
    
    @Override
    public void onClick(View v) {
        EditText et1 = (EditText)this.findViewById(R.id.entry);
        EditText et2 = (EditText)this.findViewById(R.id.entry2);
        String lastName = et1.getText().toString();
        String firstName = et2.getText().toString();
        if (lastName.length() == 0) {
            lastName = "%";
        }
        if (firstName.length() == 0) {
            firstName = "%";
        }
        Bundle bundle = new Bundle();
        bundle.putString("LastName", lastName);
        bundle.putString("FirstName", firstName);
        switch(v.getId()) {
            case R.id.Search:
                Intent i = new  Intent(this, Search.class);
                i.putExtras(bundle);
                startActivity(i);
                c2.close();
                c3.close();
                break;
            case R.id.Near_Me:
                Intent j = new  Intent(this, SearchNearMe.class);
                startActivity(j);
    
        }       
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone please tell me how to add a C++ file in to an
Can anyone please tell/suggest me how can i store and retrieve comments multiple/different values
Can anyone please tell me how to Add resources (image, string etc) in 'Resources.resx'
Can anyone please tell me how to extract this kind of data : [{number:8457215152,type:Cell,state:LA,country:US,tz:CT,zip:70546,msa:0},{number:4363685555,type:Cell,state:LA,country:US,tz:CT,zip:70546,msa:0}]
Can anyone please tell me how they accomplished disabling the bounce effect in safari
can anyone please tell me how can i retrieve data in jquery when i
Can anyone please tell me how to do a percent sign in objective C
Can anyone please tell me how I can write a bash shell script that
Can anyone please tell what is change request management tool and what is involved
Can anyone please tell me why compiling a C# application with a .cs file

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.