Hai All,
I am new to Android programming and got a problem in radioButton which thru constant effort not able to fix it.
Requirement: My project is creating 4 radio buttons at run time and on click of 1st to 3rd radio button, i must display the radio button ID and on click of 4th RD Button, i must create a edit text box where the user has to enter a data.
Now able to create d radio buttons but when i try to choose any buttons, am not able to display its ID .
Whr am i wrong in d coding. I have created a RadioGroup ID in my layout.
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.showradioscreen);
View linearLayout = findViewById(R.id.showradioscreeninfo);
//Dynamically create radio buttons
radioGroup = new RadioGroup(this);
radioGroup.setOrientation(RadioGroup.VERTICAL);
for(int i = 0; i < 4; ++i)
{
radioButton[i] = new RadioButton(this);
radioGroup.addView(radioButton[i]);
radioButton[i].setId(i);
radioButton[i].setText("RD_" + i);
}
((LinearLayout) linearLayout).addView(radioGroup);
radio_group = (RadioGroup) findViewById(R.id.radio_group1);
radio_group.setOnClickListener(new OnClickListener()
{
public void onClick(View view)
{
onRadioButtonClick(view);
}
});
}//end of onCreate()
public void onRadioButtonClick(View v)
{
int _selectedIP = radioGroup.getCheckedRadioButtonId();
RadioButton checkedButton = (RadioButton)radio_group.findViewById(_selectedIP);
boolean isChecked = ((RadioButton) v).isChecked();
switch(v.getId())
{
case 1:
EditText lEditText = new EditText(this);
lEditText.setText(1);//
break;
case 2:
EditText lEditText1 = new EditText(this);
lEditText1.setText(2);//
break;
}
}