Android ListView with RadioButton in singleChoice mode and a custom row layout

前端 未结 7 1831
野趣味
野趣味 2020-12-06 04:13

I have a ListView, which is in singleChoice mode. All I want is to display a RadioButton to the side, that when clicked highlights to say i

相关标签:
7条回答
  • 2020-12-06 05:14

    I've just had a similar problem. It seemed that it was related to views recycling. But I added Log's everywhere and noticed that the recycling handling was fine. The problem was RadioButtons handling. I was using:

    if(answer == DBAdapter.YES){
       rbYes.setChecked(true); 
       rbNo.setChecked(false);                    
    }
    else if(answer == DBAdapter.NO){
       rbYes.setChecked(false); 
       rbNo.setChecked(true);
    }
    else{
      rbYes.setChecked(false); 
      rbNo.setChecked(false);
    }                
    

    and the correct way of doing it is:

    if(answer == DBAdapter.YES){
       rbYes.setChecked(true); 
    }
    else if(answer == DBAdapter.NO){
       rbNo.setChecked(true);
    }
    else{
       RadioGroup rg = (RadioGroup)(holder.answerView);
       rg.clearCheck();
    }                
    
    0 讨论(0)
提交回复
热议问题