当我在第一行单击radiobutton时,为什么还会点击另一行中的radiobutton?

时间:2018-05-09 14:22:58

标签: android listview radio-button

我在listview中有3个radiobutton,当我在第一行点击radiobutton时,当我向下滚动列表视图时,另外一个radiobutton也会被点击。

如何解决?

Radiobutton点击了第一行

Radiobutton clicked in first row

点击了另一行

another row is clicked too

  

这是我的适配器代码

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

    final ViewHolder holder;

    if (convertView == null) {
        holder = new ViewHolder();
        convertView = inflater.inflate( R.layout.item_listview, null);
        holder.tvAlat = (TextView) convertView.findViewById(R.id.tv_alat);

        holder.tvpengecekan = (TextView) convertView.findViewById(R.id.tv_pengecekan);

        holder.tvnormal = (TextView) convertView.findViewById(R.id.tv_normal);

        convertView.setTag(mPengecekanList.get(position).getId_pengecekan());
        holder.baik = (RadioButton) convertView.findViewById(R.id.B);
        holder.rusakringan = (RadioButton) convertView.findViewById(R.id.RR);
        holder.rusakberat = (RadioButton) convertView.findViewById(R.id.RB);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    holder.tvAlat.setText(mPengecekanList.get(position).getNama_alat());
    holder.tvpengecekan.setText(mPengecekanList.get(position).getPengecekan());
    holder.tvnormal.setText(mPengecekanList.get(position).getNormal());

    holder.baik.setTag(position);
    holder.rusakringan.setTag(position);
    holder.rusakberat.setTag(position);

    holder.baik.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View v) {
              selectedAnswers.set(position, "1");
                 }});

holder.rusakringan.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View v) {
              selectedAnswers.set(position, "2");
                 }});
holder.rusakberat.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View v) {
              selectedAnswers.set(position, "3");
                 }});}

1 个答案:

答案 0 :(得分:0)

我在代码中看不到任何问题

  

但是,如果您为其他ID选择的内容选择唯一ID,那肯定是   未选中

所以尝试调试你的代码,你会发现与另一个选择的无线电采用相同的ID或相同的标签,如何