小编Coc*_*o12的帖子

如何将单选按钮状态保存到已保存/共享首选项?

我可以在保存的首选项中保存字符串,但无法保存单选按钮。

public class PersonalDetailsf extends Activity {

    private SharedPreferences sharedPreferences;  

    private RadioGroup radioGroup;
    private RadioButton radioSexButton;
    private RadioButton rdoMale;
Run Code Online (Sandbox Code Playgroud)

这是我的创建:

    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    String strAge = Integer.toString(age);
    String strHeight = Integer.toString(height);
    String strWeight = Integer.toString(weight);

    name = loadSavedPreference("name");
    strAge = loadSavedPreference("strAge");
    strHeight = loadSavedPreference("strHeight");
    strWeight = loadSavedPreference("strWeight");

    etName.setText(name);
    etAge.setText(strAge);
    etHeight.setText(strHeight);
    etWeight.setText(strWeight);
Run Code Online (Sandbox Code Playgroud)

这是在按钮后面的 onCLick 中,我在其中使用单选按钮并保存字符串:

            Name = etName.getText().toString();
            age = (int) Double.parseDouble(etAge.getText().toString());
            height = (int) Double.parseDouble(etHeight.getText().toString());
            weight = (int) Double.parseDouble(etWeight.getText().toString());


            int selectedId = radioGroup.getCheckedRadioButtonId();

            radioSexButton = (RadioButton) findViewById(selectedId);
            rdoMale = (RadioButton) …
Run Code Online (Sandbox Code Playgroud)

android radio-button sharedpreferences

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

radio-button ×1

sharedpreferences ×1