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
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