source code untuk membuat radio button
1. untuk file 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">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hobi yang
diminati :"></TextView>
<RadioGroup android:id="@+id/rBtnGrp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton android:id="@+id/bacaRBtn"
android:text="Membaca"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<RadioButton android:id="@+id/nulisRBtn"
android:text="Menulis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<RadioButton android:id="@+id/nontonRBtn"
android:text="Menonton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<RadioButton android:id="@+id/lainRBtn"
android:text="lainnya"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</RadioGroup>
</LinearLayout>
package app.seamolec.zelviarb;
import android.app.Activity;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
public class ZelviaradiobuttonActivity extends Activity {
/** Called when the
activity is first created. */
@Override
public void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
RadioGroup rdgrp
= (RadioGroup)findViewById(R.id.rBtnGrp);
RadioButton
newRadioBtn = new RadioButton(this);
newRadioBtn.setText("Traveling");
rdgrp.addView(newRadioBtn);
newRadioBtn.setChecked(true);
}
}
Tidak ada komentar:
Posting Komentar