1

私は4つのアクティビティをJavaファイルと呼んでいます - activity1.java、activity2.java、activity3.java、activity4.java、およびxmlファイル - activity_1.xml、activity_2.xml、activity_3.xml、activity_4.xml

現在、アクティビティ 1 にあります - 2 つのラジオ ボタンとアクティビティ 2 に移動するためのボタンを持つラジオ グループがあります。

現在、アクティビティ 2 に - アクティビティ 1 でクリックされたラジオ ボタンに基づいて、アクティビティ 3 またはアクティビティ 4 に移動するボタンがあります。

アクティビティ 2 を削除し、アクティビティ 1 の if 条件を使用してアクティビティ 3 または 4 に移動できますが、アクティビティ 2 が必要なのは間違いありません

バンドルや共有設定に慣れていない

どのように?この点に関するヘルプ

4

2 に答える 2

0

インテントを使用して、アクティビティ間で値を渡すことができます。最初のアクティビティ:

 Intent intent = new Intent(this, SecondActivity.class);
 intent.putExtra("someName", valueOfRadioButton);
 startActivity(intent);

次のアクティビティでは、onCreate渡した値を次のように取得できます (整数の場合)。

 getIntent().getIntExtra("someName", someDefaultValue);

これで、クエリする変数ができました。値に応じて、好きなアクティビティを起動します。

于 2015-03-23T13:49:44.403 に答える
0

使用する

Intent startSecondActivityIntent = new Intent(FirstActivity.this,SecondActivity.java);
Intent.putExtra("nameOfValue",value);
startActivity(startSecondActivityIntent);

次に、この値を取得できます。

getIntent().getIntExtra("nameOfValue",defaultValue);

または、SharedPreferences を使用できます

SharedPreferences sp = getSharedPreferences("nameOfPreferences",MODE_PRIVATE);
    SharedPreferences.Editor editor = sp.edit();
    editor.putString("nameOfValue",value);
    editor.commit();

そして、他のアクティビティでこの値を取得します:

SharedPreferences sp = getSharedPreferences("nameOfPreferences",MODE_PRIVATE);
String value = sp.getString("nameOfValue",defaultValue);
于 2015-03-23T15:36:10.910 に答える