1

I have a spinner and I have added a custom style to spinner. Problem is when I select an item it doesnt show up on the spinner but when I use android spinner style it shows what I selected on the spinner. Is there any more coding to add to make it work? Otherwise everthing of the spinner works. I have written the app when an item is selected in spinner to show a text. These things work. But it doesnt show what I selected.

Here is my code

MyAdapter dataAdapter3 = new MyAdapter(this, R.layout.spinner, list3); spinner1.setAdapter(dataAdapter3); 

list 3 referes a list

List<String> list3 = new ArrayList<String>(); 

Here is the class for custom spinner style

public class MyAdapter extends ArrayAdapter<String> { private List<String> listString = new ArrayList<String>(); public MyAdapter(Context context, int textViewResourceId, List<String> objects) { super(context, textViewResourceId, objects); this.listString = objects; } @Override public View getDropDownView(int position, View convertView,ViewGroup parent) { return getCustomView(position, convertView, parent); } @Override public View getView(int position, View convertView, ViewGroup parent) { return getCustomView(position, convertView, parent); } public View getCustomView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater=getLayoutInflater(); View row=inflater.inflate(R.layout.spinner, parent, false); TextView label=(TextView)row.findViewById(R.id.textView1); label.setText(listString.get(position)); return row; } } 

please can anybody tell whether I have done any mistake here? This is how spinner is shows when I selected item enter image description here

2 Answers 2

8

I tried several days on this problem. Actually code is pretty ok. problem was in the spinner.xml file. I had added a large padding to textview. Therefore, though spinner works it is not visible the selected item on spinner. Point is I forget xml file. :D

Sign up to request clarification or add additional context in comments.

Comments

0

Modify the padding in the layout spinner.xml file to a lower value, for ex:

<TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="8dp" android:textColor="#000000" android:textSize="14sp" /> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.