繁体   English   中英

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

[英]Single selection checkbox in custom listview

我想在我的自定义列表视图中使用单选复选框。这是我的自定义适配器中的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;
}

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

写这行holder.check.setChecked(checkarry [position]);

在点击侦听器之后,我认为这样可以

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM