RadioButtonDemo.java
--------------------------------------
package com.kites.radiotest;
import android.app.Activity;
import android.os.Bundle;
import android.widget.RadioGroup;
public class RadioButtonDemo extends Activity
implements RadioGroup.OnCheckedChangeListener{
RadioGroup rg;
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
rg=(RadioGroup)findViewById(R.id.rg);
rg.setOnCheckedChangeListener(this);
}
public void onCheckedChanged(RadioGroup group,
int checkedId) {
if (group==rg) {
if (checkedId==R.id.r1) {
}
else if (checkedId==R.id.r2) {
}
else if (checkedId==R.id.r3) {
}
}
}
}
-----------------------------------------------------------------------------------------------------------------------------
main.xml
----------------
<?xml version="1.0" encoding="utf-8"?>
<RadioGroup
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:id="@+id/rg"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RadioButton android:id="@+id/r1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio1" />
<RadioButton android:id="@+id/r2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio2" />
<RadioButton android:id="@+id/r3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio3" />
</RadioGroup>
-------------------------------------------------------------------------------------------------------------------------------
--------------------------------------
package com.kites.radiotest;
import android.app.Activity;
import android.os.Bundle;
import android.widget.RadioGroup;
public class RadioButtonDemo extends Activity
implements RadioGroup.OnCheckedChangeListener{
RadioGroup rg;
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
rg=(RadioGroup)findViewById(R.id.rg);
rg.setOnCheckedChangeListener(this);
}
public void onCheckedChanged(RadioGroup group,
int checkedId) {
if (group==rg) {
if (checkedId==R.id.r1) {
}
else if (checkedId==R.id.r2) {
}
else if (checkedId==R.id.r3) {
}
}
}
}
-----------------------------------------------------------------------------------------------------------------------------
main.xml
----------------
<?xml version="1.0" encoding="utf-8"?>
<RadioGroup
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:id="@+id/rg"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RadioButton android:id="@+id/r1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio1" />
<RadioButton android:id="@+id/r2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio2" />
<RadioButton android:id="@+id/r3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio3" />
</RadioGroup>
-------------------------------------------------------------------------------------------------------------------------------
No comments:
Post a Comment