android spinner set tag

倾然丶 夕夏残阳落幕 提交于 2019-12-24 07:30:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!