簡単な質問です。インテントを使用して、チェックされたラジオ ボタンの値を他のアクティビティに渡すにはどうすればよいですか? 値を保存するために共有設定も使用する必要がありますか?
「ユーザーがラジオボタン(赤、青、緑、黄色など)を選択すると、すべてのテキストビューの色がすべてのアクティビティで変更されます。
public class Text_Colour extends Activity implements RadioGroup.OnCheckedChangeListener {
RadioButton rb1, rb2, rb3, rb4;
TextView tv2;
RadioGroup rg1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.colours);
tv2 = (TextView)findViewById(R.id.textview2);
rb1 = (RadioButton) findViewById(R.id.radioButton1);
rb2 = (RadioButton) findViewById(R.id.radioButton2);
rb3 = (RadioButton) findViewById(R.id.radioButton3);
rb4 = (RadioButton) findViewById(R.id.radioButton4);
rg1 = (RadioGroup) findViewById(R.id.radiogroup1);
rg1.setOnCheckedChangeListener(this);
}
public void onCheckedChanged(RadioGroup rg1, int r) {
// TODO Auto-generated method stub
if (r==rb1.getId()) {
tv2.setTextColor(Color.RED);
}
if (r==rb2.getId()) {
tv2.setTextColor(Color.YELLOW);
}
if (r==rb3.getId()) {
tv2.setTextColor(Color.GREEN);
}
if (r==rb4.getId()) {
tv2.setTextColor(Color.BLUE);
}
else {
tv2.setTextColor(Color.BLACK);
}
}
}
御時間ありがとうございます。