I am trying to make a custom style for android spinner, however there are several problems.
I have noticed in many examples, they pass array to getCustomView method. I am wondering whether I can pass a list instead of an array.
Second problem is why they have declared variable and initialized in class variable scope?
They have declared arrays like this.
String []data1={"Brainbitz:java","Brainbitz:Android","Brainbitz:Embedded Systems","Brainbitz:PHP"};
in class variable scope. But when I try to do for the list I get an error. why?
Third is,
If we can pass list to getCustomView how do I do that? Here is the link to the tutorial tutorial
I am considering this source code.
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(list3.get(position));
// TextView sub=(TextView)row.findViewById(R.id.textView2);
// sub.setText(data2[position]);
//
// ImageView icon=(ImageView)row.findViewById(R.id.imageView1);
// icon.setImageResource(images[position]);
return row;
}
In above code I don’t know the syntax to pass position to list3 list type reference.
Please be kind enough to explain this.
First of All,
You are using default
ArrayAdapterClass..Which Uses
Stringclass for data bind. If you want to make anArrayAdapterwith aArrayListorListyou have to make a Custom Adapter by extendingArrayAdapter<Custom_Class>orBaseAdapter.The
ArrayAdapterclass can handle any Java object as input. It maps the data of this input to a TextView in the layout.ArrayAdapteruses thetoString()method of the data input object to determine the String which should be displayed.Look at How to use ArrayAdapter<myClass> and this Tutorial
Update: