问题
I created the radio buttons dynamically and set them in the radio group and it is working good but when i click the radio buttons to get the value but onclick is not working here is the code: in this when i click on checked change listner there is nothing happens i also taost it to show either onclick is working or not but nothing prints. please help thanks in advance.
try {
Thread.sleep(1000);
voterNA=dbcon.GetVoterNA(id);
LinearLayout ll=new LinearLayout(context);
ll.setOrientation(LinearLayout.VERTICAL);
ImageView iv=null;//new ImageView(context);
LinearLayout.LayoutParams prams=new RadioGroup.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
prams.setMargins(2, 2, 2, 2);
rg=new RadioGroup(context);
ll.setLayoutParams(prams);
rg.setBackgroundColor(Color.LTGRAY);
rg.setLayoutParams(prams);
rg=dbcon.showNationalCan(rg, context,iv,voterNA);
ll.addView(rg);
((ViewGroup)findViewById(R.id.NRG)).addView(ll);
final RadioGroup rg1=(RadioGroup)findViewById(R.id.NRG);
rg1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
for(int i=0; i<rg.getChildCount();i++)
{
RadioButton rbtn=(RadioButton)rg.getChildAt(i);
if(rbtn.getId()==checkedId)
{
serial=rbtn.getId();
Toast.makeText(context, serial, 1).show();
flag=true;
return;
}
else
{
Toast.makeText(context, "Else", 1).show();
rbtn.setChecked(false);
}
}
}
});
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
来源:https://stackoverflow.com/questions/25617537/dynamic-radio-buttons-are-not-working-when-click-the-radio-group-to-checkchangel