0

如果有人帮助我使用此代码,我将不胜感激:

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);

    }

});

}
}

提前致谢.....

4

2 回答 2

0

我已经通过改变解决了:

SharedPreferences preferences = getSharedPreferences("PREFERENCE", 0);

对此:

SharedPreferences preferences = getSharedPreferences("help", 0);

感谢 Raghunandan 的重播....

但我仍然没有解决 RadioButton 需要帮助.....请

于 2013-11-03T09:02:11.433 回答
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);
    }   
}
于 2013-11-03T11:02:18.000 回答