0

I have added a spinner in an application which gives the package information in only a word or couple of word. it seems like regular dropdown menu. I tried to make changes in simple_spinner_dropdown_item.xml file but it does not help and also it is having a radio button which i dont require.

I am done with handling functionality and only needed to change design of that dropdown menu of spinner.

for that i am using checkedTextView like:

service_provider_spinner.setPopupBackgroundResource(R.drawable.ser_menu);

now i don't want that layout rather i like to add a background for each item and also want to set text padding and margin and all that. How can i do this in java file specificly and also in XML.

balaji koduri
  • 1,321
  • 9
  • 25
kiturk3
  • 549
  • 10
  • 30

1 Answers1

0

You can customize the spinner_layout and spinner_dropdown_layout by simply creating an xml layout for both containing only TextView like this as shown.

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
 />

And you can apply this xml to your adapter as shown below:

ArrayAdapter<String> adapter= new ArrayAdapter<String>(
            getActivity(), R.layout.your_spinnerLayout, yourArray);
    adapter.setDropDownViewResource(R.layout.your_spinner_dropdown_layout);
    spinner.setAdapter(adapter);
Mukesh Rana
  • 4,051
  • 3
  • 27
  • 39
  • i also want to give a background to each item. Can i do the same in xml file with android:background="..."?? – kiturk3 Oct 29 '14 at 12:06