Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have created a spinner having categories, and now I want to add the doctor's name in the subcategories, but I am not able to do it.

What I have tried:

       String[] categories = {"All","Surgeon","Pediatrician","Cardiologist","Dermatologist"};
        ArrayAdapter aa = new ArrayAdapter(this,android.R.layout.simple_spinner_item,categories);
        aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//Setting the ArrayAdapter data on the Spinner
        drspin.setAdapter(aa);
        drspin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                String a = drspin.getSelectedItem().toString();
                sd.setText(a);


            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
Posted
Comments
Richard MacCutchan 5-May-21 4:57am    
"add the doctor's name in the subcategories, but I am not able to do it."
Where is the name obtained from, where do you want to display it, and what do you mean by "I am not able to do it"?
David Crow 5-May-21 8:03am    
Have you considered an ExpandableListView instead? It's made for such a thing.
nalish Rathi 5-May-21 8:07am    
No, I haven't tried it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900