如何在android中设置复选框的标签?

时间:2013-12-26 10:37:15

标签: android arrays android-arrayadapter

在我的活动中,我有一个字符串数组,其中包含一些数字。

我有一个适配器,它由复选框组成,如下所示。

public class sendivitesadapter extends ArrayAdapter<Item>{
    private Context context;
    private ArrayList<Item> items;
    private qrusers qrusers1;
    private LayoutInflater vi;
    private String[] array;


    public sendivitesadapter(Context context,ArrayList<Item> items) {
        super(context, 0,items);

        this.context= context;
        this.qrusers1 =(qrusers) context;
        this.items = items;
        vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    }
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return super.getCount();
    }

    @Override
    public Item getItem(int position) {
        // TODO Auto-generated method stub
        return super.getItem(position);
    }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            View v = convertView;

            final Item i = items.get(position);

            if (i != null) {
                if(i.isSection()){
                    SectionItem si = (SectionItem)i;
                    v = vi.inflate(R.layout.checkboxlist, null);

                    v.setOnClickListener(null);
                    v.setOnLongClickListener(null);
                    v.setLongClickable(false);

                    final TextView sectionView = (TextView) v.findViewById(R.id.list_item_section_text);
                    sectionView.setText(si.getTitle());

                }else{
                    sendItem ei = (sendItem)i;
                    v = vi.inflate(R.layout.checkboxlist, null);
                    final TextView title = (TextView)v.findViewById(R.id.contactname);
                    final TextView subtitle = (TextView)v.findViewById(R.id.companyname);
                    final CheckBox checkBox=(CheckBox)v.findViewById(R.id.checboxlist);
                    checkBox.setTag(qrusers1.uid);



                //    Log.e("IDDDDDDD", text);
                    //checkBox.setTag("12");
                    checkBox.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            // TODO Auto-generated method stub
                            String s=(String) v.getTag();
                            Log.e("IDDDDDDDDDDDDDDDDDDDDDD", s);
                        }
                    });
                    if (title != null) 
                        title.setText(ei.contactname);
                    if(subtitle != null)
                        subtitle.setText(ei.companyname);

                }
            }
            return v;
        }




}

现在我必须用我在我的活动中获得的uid [i]设置标签复选框。我怎么能这样做? 我从webservice获取uid的活动。

@Override
    protected void onPostExecute(String result) {
        JSONArray jarray;

        try {
            jarray= new JSONArray(result);

            name= new String[jarray.length()];
            company=new String[jarray.length()];
            uid=new String[jarray.length()];
            for (int i=0;i<jarray.length();i++){



                JSONObject jobj = jarray.getJSONObject(i);
                name[i]=    jobj.getString("Name");
                company[i]=jobj.getString("Company");
                uid[i]=jobj.getString("UserID");
                System.out.println(uid[i]);

0 个答案:

没有答案