Skip to content

Instantly share code, notes, and snippets.

@khannedy
Created November 2, 2011 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save khannedy/1334133 to your computer and use it in GitHub Desktop.
Save khannedy/1334133 to your computer and use it in GitHub Desktop.
RadioButton di Android
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
}
});
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
TextView textView = (TextView) findViewById(R.id.textStatus);
if (checkedId == R.id.radioLakiLaki) {
textView.setText("Anda Laki-Laki");
} else {
textView.setText("Anda Perempuan");
}
}
});
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Jenis Kelamin Anda :" />
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/radioLakiLaki"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Laki-Laki" />
<RadioButton
android:id="@+id/radioPerempuan"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Perempuan" />
</RadioGroup>
<TextView
android:id="@+id/textStatus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/radioLakiLaki"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Laki-Laki" />
<RadioButton
android:id="@+id/radioPerempuan"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Perempuan" />
</RadioGroup>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</RadioGroup>
</LinearLayout>
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
TextView textView = (TextView) findViewById(R.id.textStatus);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment