R.Rajkumar R.Rajkumar - 1 month ago 16
Android Question

How to set same appearance for spinner in XML design?

I'm using two spinner in my activity but each spinner having different appearance. Anyone can help me to fix this kind of error???
This is first spinner image

This is second spinner image (Please see the image)

String [] values =
{"All Town","Paris","Kodambakkam","Nungambakkam","T.Nagar","Egmore"};
Spinner spinner = (Spinner) v.findViewById(R.id.town);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getActivity(), android.R.layout.simple_spinner_item, values);
adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
spinner.setAdapter(adapter);

String [] values1 =
{"Select Doctor","Doctor1","Doctor2","Doctor3","Doctor4"};
Spinner spinner1 = (Spinner) v.findViewById(R.id.doctor);
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this.getActivity(), android.R.layout.simple_spinner_item, values1);
adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
spinner1.setAdapter(adapter1);


XML:

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/town" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/doctor" /></LinearLayout>


Please help me. Thanks in advance!!!!

Answer

Try this on second spinner... you have pass first adapter object to second adapter

String [] values1 =
        {"Select Doctor","Doctor1","Doctor2","Doctor3","Doctor4"};
Spinner spinner1 = (Spinner) v.findViewById(R.id.doctor);
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this.getActivity(), android.R.layout.simple_spinner_item, values1);
adapter1.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
spinner1.setAdapter(adapter1);