I have tried this code..It will display three radio buttons in a single row when the emulator starts. But I need a button event for this. i.e; if I click the button, it shou
Add a Button
and EditText
in xml and take input from editText to variable inputValue
and try this,
public class MyActivity extends Activity {
/**
* Called when the activity is first created.
*/
LinearLayout ll=null;
ViewGroup vwgroup;
Button btnClick;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
vwgroup=((ViewGroup)findViewById(R.id.radiogroup)
btnClick=(Button)findViewById(R.id.button1);
btnClick.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if(ll!=null)
viewgroup.removeView(ll);
ll = new LinearLayout(this);
for(int i = 1; i < inputValue; i++) {
RadioButton rdbtn = new RadioButton(this);
rdbtn.setId(View.generateViewId());
rdbtn.setText("Radio " + rdbtn.getId());
ll.addView(rdbtn);
}
vwgroup.addView(ll);
}
});
}
}