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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:15:41+00:00 2026-05-27T04:15:41+00:00

I am developing an android app in which I have 3 spinners populated from

  • 0

I am developing an android app in which I have 3 spinners populated from a database called
Department,Practice and Address

I am loading them conditionally i.e, if it is department A load Practice A,B and based on practice A address is set.

Then I am saving these positions in an another database table by getSelectedItemPosition().

Now when I am trying them to 3 variables deptpos,practipos and addrpos.
But when I use setSelection after initializing the spinners it is showing only correct position for department rest of them are not working 🙁

Here is my code

//Initializing the shared preferences variable
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    //Loading the database in writable format
    db=mydbhelper.getWritableDatabase();

    //For Medicines Table
    try{
        //For medicines
        Cursor medspin = db.query("medicines", null,"_id="+prefs.getInt("pos",1),null,null,null,null);
        medspin.moveToFirst();
        //Filling the variables to set selemedspintion
        deptpos=medspin.getInt(medspin.getColumnIndex("provider_department"));
        practipos=medspin.getInt(medspin.getColumnIndex("provider_practice"));
        addrpos=medspin.getInt(medspin.getColumnIndex("provider_address"));
        hsname=medspin.getString(medspin.getColumnIndex("healthsystem"));
        medspin.close();
        Toast td=Toast.makeText(this,"Loaded dept is "+deptpos+"Loaded Provider is "+practipos+"Address is "+addrpos,Toast.LENGTH_LONG);
        td.show();


    }
    catch(Exception e){
        Log.e("Error","Error",e);
    }




    try{

        //Cursor
        Cursor depcur = db.rawQuery("SELECT _id,department,"+prefs.getString("hsname",null)+ " FROM dept_masterdata WHERE "+prefs.getString("hsname",null)+"=1",null);
        depcur.moveToFirst();
        startManagingCursor(depcur);
        String[] from = new String[]{"department"};
        int[] to = new int[] { android.R.id.text1 };
         // Now creating an array adapter and set it to display using my row
        //Adaptor for Department
        SimpleCursorAdapter deptype =new SimpleCursorAdapter(this,android.R.layout.simple_spinner_item, depcur, from, to);
        deptype.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        dep.setAdapter(deptype);


    }
    catch(Exception e){
        Log.e("Error","Error",e);
    }
     //Now determine which department is selected
    //Department
    dep.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent,View view,int pos,long id){
            deptid=dep.getSelectedItemId();


            //Setting the practice spinner based on the department selected
            Cursor pracur = db.rawQuery("SELECT _id,practice,dept_link,hs_id FROM practice_masterdata WHERE dept_link="+deptid+" AND hs_id="+(prefs.getInt("hsid",0)),null);
            pracur.moveToFirst();
            startManagingCursor(pracur);
            String[] from1 = new String[]{"practice"};
            int[] to1 = new int[]{android.R.id.text1};
            SimpleCursorAdapter practype =new SimpleCursorAdapter(view.getContext(),android.R.layout.simple_spinner_item, pracur, from1, to1);
            practype.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            pra.setAdapter(practype);
        }
        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });
    //Practice
    pra.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent,View view,int pos,long id){

            practid=pra.getSelectedItemId();


            //Setting the address  based on the practice selected
            Cursor addcur =db.rawQuery("SELECT * FROM address_masterdata WHERE practice_link="+practid,null);
            addcur.moveToFirst();
            startManagingCursor(addcur);
            String[] from2 = new String[]{"address"};
            int[] to2   = new int[]{android.R.id.text1};
            SimpleCursorAdapter addtype =new SimpleCursorAdapter(view.getContext(),android.R.layout.simple_spinner_item,addcur, from2, to2);
            addtype.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            add.setAdapter(addtype);
        }
        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });
    //Address
    add.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent,View view,int pos,long id){
            addrid=add.getSelectedItemId();


        }
        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });







    //Setting the spinners based on the above variables

    dep.setSelection(deptpos);
    pra.setSelection(practipos);
    add.setSelection(addrpos,false);

}

I confirmed with a toast if the variables are loading correct values. They are but it is simply not setting them :(. The strange thing is department is showing the correct setting while both practice and address are not all :(. Please kindly point out where I am going wrong

thank you

  • 1 1 Answer
  • 1 View
  • 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-27T04:15:41+00:00Added an answer on May 27, 2026 at 4:15 am

    Does practice and address have values already? If not then load data for practice and address out of depot selected listener, with by default d first as selected element.

    depots[] = loadDepots();
    depotsSpinner.setAdapter();
    depotsSpinner.setSelected(0);
    
    practice[] = loadPractice(depots[0]);
    practiceSpinner.setAdapter();
    practiceSpinner.setSelected(0);
    
    address[] = loadAddress(depots[0], practice[0]);
    addressSpinner.setAdapter();
    addressSpinner.setSelected(0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently developing an android app. I have an activity which calls a
I am developing an android app in which I have to collect date of
I am developing an android app in which I have to present the user
I am developing an android app which fetches/uploads data from/to the web service every
I'm developing an Android app in which I have to do a POST request
I am developing my first Android app. I have a ListActivity which uses the
Possible Duplicate: Remote Database access I'm developing an app for android which shoult connect
I am developing an android app which has Facebook integration in it. I have
I am developing an android app (only Widget) which displays some images from a
I am developing an android application in which I have created a database named

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.