问题
I am developing application. In that i am populating spinner from the database. I got the arrayList which consist of description and code . I need to set the code as tag for each description. Is there any possibility to add tag for individual items in spinner.
回答1:
Try simple custom adapter:
public class MySpinnerAdapter extends BaseAdapter {
private Activity context;
public CitiesSpinnerAdapter(Activity context){
this.context=context;
}
@Override
public int getCount() {
return 0;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
RelativeLayout item= (RelativeLayout)context.getLayoutInflater().inflate(R.layout.<your spinner item layout name>, null);
//set your data to layout components
item.setTag(<your tag object>);
return item;
}
来源:https://stackoverflow.com/questions/9294319/android-spinner-set-tag