快速提问。我将如何使用意图将选中的单选按钮值传递给其他活动?我是否还需要使用共享偏好来保存价值?
我想做类似“当用户选择单选按钮(例如:红色,蓝色,绿色,黄色)并且所有文本视图的颜色将在所有活动中更改时。
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);
}
}
}
谢谢你的时间。