package app.test;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.RadioGroup;
public class Test extends Activity {
protected static final String TAG = "RadioGroup";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
RadioGroup radGrp = (RadioGroup) findViewById(R.id.main);
int RadioButtonId = radGrp.getCheckedRadioButtonId();
radGrp.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup arg0, int id) {
switch (id) {
case -1:
Log.v(TAG, "Choices!!!");
break;
case R.id.Num1:
Log.v(TAG, " Number 1 ");
break;
case R.id.
Num2
:
Log.v(TAG, "
Number 2
");
break;
case R.id.
Num3
:
Log.v(TAG, "
Number 3
");
break;
default:
Log.v(TAG, "Problem?");
break;
}
}
});
}
}
/////////////////////////////////////////
//main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RadioButton
android:id="@+id/anotherRadBtn"
android:text="Outside"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioGroup android:id="@+id/radGrp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/
Num1
"
android:text="Chicken"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioButton
android:id="@+id/
Num2
"
android:text="Fish"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioButton
android:id="@+id/
Num3
"
android:text="Steak"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:text="My Favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RadioGroup>
</LinearLayout>
No comments:
Post a Comment