私は小さな選択フォームのようなことをしたいと思います。Android - Radiobuttonイベントをクリックして新しいアクティビティに移動します
私は最初のラジオグループの1つを選択し、2番目のラジオグループの1つを選択すると、新しい活動に私を連れて行くクリックイベントをしたいと思います。 私は2つの放射性グループを持っています。
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton android:id="@+id/physic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="physic"
android:onClick="onRadioButtonClicked"/>
<RadioButton android:id="@+id/math"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="math"
android:onClick="onRadioButtonClicked"/>
</RadioGroup>
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton android:id="@+id/theories"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="theories"
android:onClick="onRadioButtonClicked"/>
<RadioButton android:id="@+id/problems_solving"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="problem solving"
android:onClick="onRadioButtonClicked"/>
</RadioGroup>
私は私のボタンを宣言し、以下のようにonRadioButtonClicked使用しようとした:
public void onRadioButtonClicked(View view) {
boolean checked = ((RadioButton) view).isChecked();
switch(view.getId()) {
case R.id.math:
if (checked)
switch(view.getId()) {
case R.id.problems_solving:
if (checked)
showFirstWord("math problem resolution");
break;
case R.id.theories:
if (checked)
showSecondWord("math theories");
break;
}
break;
case R.id.physic:
if (checked)
switch(view.getId()) {
case R.id.problems_solving:
if (checked)
showThirdWord("physic problem solving");
break;
case R.id.theories:
if (checked)
showFourthWord("physic theories");
break;
}
break;
}
}
私は関数内の文字列は、以下のような他の活動にテキストビューに表示する:
private void showFirstWord (String text) {
Intent first_word = new Intent(this, FirstActivity.class);
first_word.putExtra("key", text);
startActivity(first_word);
}
private void showSecondWord (String text) {
Intent second_word = new Intent(this, SecondActivity.class);
second_word.putExtra("key", text);
startActivity(second_word);
}
private void showThirdWord (String text) {
Intent third_word = new Intent(this, ThirdActivity.class);
third_word.putExtra("key", text);
startActivity(third_word);
}
private void showFourthWord (String text) {
Intent fourth_word = new Intent(this, FourthActivity.class);
fourth_word.putExtra("key", text);
startActivity(fourth_word);
}
Androidデベロッパーからこのページをフォローしようとしましたが、それでも何をすればよいか分かりません:
私の方法は正しいとは思われません。他のアクティビティに表示される文字列を取得できません。今の私の理性は大丈夫ですか、別の方法を勉強すべきですか?
感謝:)
1から4の機能が何であるか分かりません。ただし、クリックされたビューはRadioGroup(ViewGroupは常にView)*または*クリックされたViewはRadioButtonです。 view.getId()は== R.id.firstGroupと同時に== R.id.answer1_1にすることはできません。しかしそれは意図の質問であなたを助けません。この質問に答えるために、私は関数が何をするのかを見ていく必要があります。 – 0X0nosugar
申し訳ありません私は少し明確にしたいことを作ってみました。もう少し理解できるといいなあと思います。 :) –