【问题标题】:Custom ListPreference RadioButton doesn't save selected Item [closed]自定义 ListPreference RadioButton 不保存所选项目 [关闭]
【发布时间】:2012-09-06 06:01:28
【问题描述】:

我正在根据现有的 SO 问题 custom row in a listPreference? 构建一个项目。在我的程序版本中,选择单选按钮不起作用;最后检查的项目没有被保存。我的模拟项目是here,背景为黑色。

【问题讨论】:

  • 你的代码呢?我们应该猜吗?

标签: android


【解决方案1】:

做这些改变(部分代码):

public void onClick(View v)
                    {
                        for(RadioButton rb : rButtonList)
                        {
                            if(rb.getId() != position)
                                rb.setChecked(false);
                        }

                        int index = position;
                        String value = entryValues[index].toString();
                        editor.putString("yourPref", value);
                        editor.commit();
                        Dialog mDialog = getDialog();
                        mDialog.dismiss();

CustomHolder(View row, int position)
        {    
            text = (TextView)row.findViewById(R.id.custom_list_view_row_text_view);
            text.setText(entries[position]);
       rButton =(RadioButton)row.findViewById(R.id.custom_list_view_row_radio_button);
            rButton.setId(position);

            if(entryValues[position].toString().equalsIgnoreCase(FontSize))
            {
                rButton.setChecked(true);
            }

if(isChecked)
                    {
                        for(RadioButton rb : rButtonList)
                        {
                            if(rb != buttonView)
                                rb.setChecked(false);
                        }

                        int index = buttonView.getId();
                        String value = entryValues[index].toString();
                        editor.putString("yourPref", value);
                        editor.commit();

和FontSize变量填写构造函数:

SharedPreferences fontsizesetting = PreferenceManager.getDefaultSharedPreferences(context);
    String temp = fontsizesetting.getString("yourPref","16");

【讨论】:

  • 嘿,如果我为多个 listPreferences 实现它,我怎样才能得到"key",因为这里它被硬编码为"yourPref"
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多