显示另一个 activity 而不是 MainActivity
Displaying another activity instead MainActivity
如何显示另一个 activity 而不是主要的,如果在设置中,在 RadioButtons 列表中标记了一个特定的项目?
例如:
如果你 select A - activity A 显示。
如果你 select B - activity B 显示。
如果你 select C - activity C 显示。
您可以使用 sharedPreferences。如果选择第一个单选按钮,只需将 A 存储在 sharedPreferences 中,如果选择第二个单选按钮,则存储 B,依此类推。
创建intent时,可以查看CallingActivity SharedPreference中存储的内容,如果是默认值则调用main,否则使用switch case调用具体的activity.
SharedPreferences sharedPref = getSharedPreferences("CallingActivity", Context.MODE_PRIVATE);
SharedPreferences.Editor sEditor = sharedPref.edit();
sEditor.putString("ActivityName","A");
sEditor.commit();
首先获取radio组中当前选中的是哪个按钮。获得当前单选按钮后,只需检查按钮的文本或标签并启动基于它的 activity。
尝试这样的事情,
radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// checkedId is the RadioButton selected
// get selected radio button from radioGroup
int selectedId = radioGroup.getCheckedRadioButtonId();
// find the radio button by returned id
radioButton = (RadioButton) findViewById(selectedId);
// toggle views on radio button click
if (radioButton.getText().toString().equals("Activity A") {
startActivity(new Intent(CurrentActivity.this, ActivityA.class))
}
else if (radioButton.getText().toString().equals("Activity B")) {
startActivity(new Intent(CurrentActivity.this, ActivityB.class))
}
else if (radioButton.getText().toString().equals("Activity C")){
startActivity(new Intent(CurrentActivity.this, ActivityC.class))
}
}
});
如何显示另一个 activity 而不是主要的,如果在设置中,在 RadioButtons 列表中标记了一个特定的项目? 例如: 如果你 select A - activity A 显示。 如果你 select B - activity B 显示。 如果你 select C - activity C 显示。
您可以使用 sharedPreferences。如果选择第一个单选按钮,只需将 A 存储在 sharedPreferences 中,如果选择第二个单选按钮,则存储 B,依此类推。 创建intent时,可以查看CallingActivity SharedPreference中存储的内容,如果是默认值则调用main,否则使用switch case调用具体的activity.
SharedPreferences sharedPref = getSharedPreferences("CallingActivity", Context.MODE_PRIVATE);
SharedPreferences.Editor sEditor = sharedPref.edit();
sEditor.putString("ActivityName","A");
sEditor.commit();
首先获取radio组中当前选中的是哪个按钮。获得当前单选按钮后,只需检查按钮的文本或标签并启动基于它的 activity。
尝试这样的事情,
radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// checkedId is the RadioButton selected
// get selected radio button from radioGroup
int selectedId = radioGroup.getCheckedRadioButtonId();
// find the radio button by returned id
radioButton = (RadioButton) findViewById(selectedId);
// toggle views on radio button click
if (radioButton.getText().toString().equals("Activity A") {
startActivity(new Intent(CurrentActivity.this, ActivityA.class))
}
else if (radioButton.getText().toString().equals("Activity B")) {
startActivity(new Intent(CurrentActivity.this, ActivityB.class))
}
else if (radioButton.getText().toString().equals("Activity C")){
startActivity(new Intent(CurrentActivity.this, ActivityC.class))
}
}
});