如果有人帮我提供此代码,我将不胜感激:
1-我有3个RadioButton用于3个活动English.class,France.class,Italian.class 用户在应用启动时选择默认语言。有人可以帮助我如何实现..?
public class Settings extends Activity {
private RadioGroup radioLaGroup;
private RadioButton radioLaButton;
private CheckBox chk_clear;
private Button btnDisplay;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
addListenerOnButton();
addListenerClear();
}
public void addListenerOnButton() {
radioLaGroup = (RadioGroup) findViewById(R.id.radioLa);
btnDisplay = (Button) findViewById(R.id.btnDisplay);
btnDisplay.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// get selected radio button from radioGroup
int selectedId = radioLaGroup.getCheckedRadioButtonId();
// find the radiobutton by returned id
radioLaButton = (RadioButton) findViewById(selectedId);
}
});
}
}
提前致谢.....
答案 0 :(得分:0)
我已经通过改变解决了:
SharedPreferences preferences = getSharedPreferences("PREFERENCE", 0);
到此:
SharedPreferences preferences = getSharedPreferences("help", 0);
感谢Raghunandan的重播......
但我仍然没有解决RadioButton neeeeed帮助.....请
答案 1 :(得分:0)
在onClick方法中使用Switch:
@Override
public void onClick(View v) {
Intent intent = null;
int selectedId = radioLaGroup.getCheckedRadioButtonId();
switch(selectedId) {
case R.id.frenchRadio:
intent = new Intent(this, French.class);
break;
case R.id.italianRadio:
intent = new Intent(this, Italian.class);
break;
case R.id.englishRadio:
intent = new Intent(this, French.class);
break;
}
if(intent != null) {
startActivity(intent);
}
}