プリファレンスアクティビティでラジオボタンを作成したい場合は、これを可能にする方法を考えてください。プリファレンスアクティビティでラジオボタンを作成する方法
また、3つのラジオボタンがあるとします。私が意図したタスクをプリフォームするために、プリファレンスアクティビティ内のラジオボタンをどのようにプログラムできますか?
プリファレンスアクティビティでラジオボタンを作成したい場合は、これを可能にする方法を考えてください。プリファレンスアクティビティでラジオボタンを作成する方法
また、3つのラジオボタンがあるとします。私が意図したタスクをプリフォームするために、プリファレンスアクティビティ内のラジオボタンをどのようにプログラムできますか?
RadioButtonsは、やりとりするボタンとして使いやすいスタイルです。
まず、あなたの活動xmlファイル
1)上のラジオ・ブロックを宣言
<?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_choice"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/choice_yes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/choice_yes"
android:checked="true" />
<RadioButton
android:id="@+id/choice_no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/choice_no" />
</RadioGroup>
</LinearLayout>
2)次に、あなたのPreferenceActivity、活動するか、使用方フラグメント()で、あなたのコンテンツを設定した後を含むビューsetContentView(R.layout.your_activity_layout);あなたは以下を実行して、あなたのラジオグループをインスタンス化することができます
さらにRadioGroup radioGroup = (RadioGroup) findViewById(R.id.radiogroup_choice);
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch(checkedId) {
case R.id.choice_yes:
// button yes was selected. do your work here
break;
case R.id.choice_no:
// button no was selected. do your work here
break;
default:
// default stuff
break;
}
}
});
を、そしてのRadioButtonは、Androidの基本的なボタンを拡張するため、アクションがしたときにトリガされるように、あなたもそれにonClickListenerを添付することができますyesとnoの間でオプションを変更する代わりに、ボタンを押してください。
よろしくお願いします。