自定义列表视图中的单选复选框

时间:2013-08-19 09:09:19

标签: android android-listview android-checkbox

我想在自定义列表视图中使用单选复选框。这是我的自定义适配器中的getview方法。

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView =convertView;
    ViewHolder holder;

    if (rowView == null) {
    rowView = inflater.inflate(R.layout.row_timeslot, parent, false);
    holder = new ViewHolder();
    holder.title = (TextView) rowView.findViewById(R.id.textView2);
    holder.layout=(RelativeLayout)rowView.findViewById(R.id.relativeLayout1);
    holder.check=(org.holoeverywhere.widget.CheckBox)rowView.findViewById(R.id.checkBox1);


    rowView.setTag(holder);
    }
    else
    {
        holder=(ViewHolder) rowView.getTag();
    }

    HashMap<String, String> trends_data= new HashMap<String, String>();
    trends_data = trendsobj.get(position);


     holder.check.setId(position);



     holder.check.setChecked(checkarry[position]);


     //for managing the state of the boolean
     //array according to the state of the
     //CheckBox



     holder.check.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (((CheckBox) v).isChecked())
            {
                checkarry[position] = true;

            }


            else
            {
                checkarry[position] = false;

            }
        }
    });


    holder.title.setText(trends_data.get(BookingActivity.KEY_TIME_TITLE));




    return rowView;
}

当我选中另一个复选框时,我想取消选中复选框。任何帮助,将不胜感激。谢谢。

1 个答案:

答案 0 :(得分:0)

写下这一行 holder.check.setChecked(checkarry [位置]);

点击监听器之后

,我认为这样做