2014-02-12 31 views
0

我想完成的是我有自己的布局的对话框首选项。我的布局只是一个带有4个单选按钮的radiogroup。我遇到的问题是我不确定我的DialogPreference.java文件的哪个方法实际上可以用单选按钮进行操作(意思是告诉哪一个被选中,然后将该值保存到共享首选项中)。目前我的DialogPreference。 java的样子:RadioGroup的自定义对话框首选项

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 
    } 
} 
} 

当对话框打开,它显示的布局正确,但我只需要援助的地方把代码利用单选按钮。

+0

工作尝试张贴您正在尝试的代码,它提供了错误。在这种情况下,[MCVE](http://stackoverflow.com/help/mcve)可能也有帮助。 –

回答

0

Puting的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 } }

+0

问题是,当我尝试引用一个单选按钮它告诉我“无法解析方法findViewById)/那是我有问题 – ez4nick

+0

@ ez4nick你应该使用View.findViewById(),就像那样查看视图= inflater.inflate (R.layout.fenlei_item,null); \t \t \t itemImage =(ImageView)view.findViewById(R.id.fenlei_item_image); –