【问题标题】:Custom Dialog preference with RadioGroup带有 RadioGroup 的自定义对话框首选项
【发布时间】:2014-02-12 01:14:03
【问题描述】:

我想要完成的是一个对话框首选项,我有自己的布局。我的布局只是一个带有 4 个单选按钮的单选组。我遇到的问题是我不确定在 DialogPreference.java 文件的哪个方法中我实际上可以使用单选按钮执行操作(意思是告诉选择了哪个,然后将该值保存到共享首选项)。目前我的 DialogPreference。 java看起来像:

public class DialogPreferences extends DialogPreference implements RadioGroup.OnCheckedChangeListener
{

RadioGroup group;
public DialogPreferences(Context oContext, AttributeSet attrs)
{
    super(oContext, attrs);
    setDialogLayoutResource(R.xml.imagechoice);

}


@Override
public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
     //I would like to do things here but when I try to for example add the reference to a radio button it gives cannot resolve method findViewById error
    }
}
}

当对话框打开时,它会正确显示布局,但我只需要有关将代码放置在何处以使用单选按钮的帮助。

【问题讨论】:

  • 尝试发布您正在尝试的代码及其给出的错误。在这种情况下,MCVE 也可能会有所帮助。

标签: java android radio-button dialog-preference


【解决方案1】:

将 RadioGroup 的工作放入 @Override public void onCheckedChanged(RadioGroup radioGroup, int checkedId) { //I would like to do things here but when I try to for example add the reference to a radio button it gives cannot resolve method findViewById error } }

【讨论】:

  • 问题是当我尝试引用一个单选按钮时它告诉我“无法解析方法 findViewById)/这就是我遇到问题的地方
  • @ez4nick 你应该使用 View.findViewById(),就像那个 View view = inflater.inflate(R.layout.fenlei_item, null); itemImage = (ImageView)view.findViewById(R.id.fenlei_item_image);
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-28
  • 1970-01-01
  • 2014-03-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多