如何访问与复选框关联的项目

时间:2011-12-23 13:22:39

标签: android

我在同一行显示一个文本和一个复选框。我需要确定哪个项目已被选中。(某种与文本的关联)

setListAdapter(new ArrayAdapter<String>(this,mRowLayout,mCallerId){
        @Override
        public View getView(int position,View convertView,ViewGroup parent){
            View row;
            if (null == convertView) {
                row = mInflater.inflate(mRowLayout, null);
            } else {
                row = convertView;
            }
            mText = (TextView)row.findViewById(R.id.callTitle);
            final String entry = getItem(position);
            mText.setText(entry);
            if(mChecked != null){
                mCheckBox = (CheckBox)row.findViewById(R.id.checkbox);
                mCheckBox.setChecked(mChecked);

                mCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView,boolean isChecked){
                        if(isChecked){
                            if(mCheckList.indexOf(entry) != -1){
                            mCheckList.add(entry);
                        }
                        }else{
                            mCheckList.remove(entry);
                        }
                    }
                });
            }
            return row;
        }
    });

0 个答案:

没有答案