Hello I’m working on android app, and I have several radio button on my app and when I click the radio button it can do what I want which is show a web page, but when I click another radio button it acts as a check box. Here is my code :
RadioButton webss = (RadioButton) findViewById (R.id.studentsite);
RadioButton webst = (RadioButton) findViewById (R.id.staffsite);
RadioButton webbaak = (RadioButton) findViewById (R.id.baak);
webss.setOnClickListener(new RadioButton.OnClickListener()
{
public void onClick(View v)
{
callintent(v);
}
});
webst.setOnClickListener(new RadioButton.OnClickListener()
{
public void onClick(View v)
{
callintent(v);
}
});
webbaak.setOnClickListener(new RadioButton.OnClickListener()
{
public void onClick (View v)
{
callintent(v);
}
});
public void callintent(View view)
{
Intent intent = null;
switch (view.getId())
{
case R.id.studentsite:
intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://studentsite.gunadarma.ac.id"));
startActivity(intent);
break;
case R.id.staffsite:
intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://staffsite.gunadarma.ac.id"));
startActivity(intent);
break;
case R.id.baak:
intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://baak.gunadarma.ac.id"));
startActivity(intent);
break;
default:
break;
}
do you have any to fix those code? Thanks.
You need to put all of your RadioButtons in your layout file inside a
RadioGroupThis way whenever one is checked, the others are automatically unchecked.