我正在尝试使用自定义日期选择器 date picker
但是我在 fragment 中膨胀根布局时遇到了这个错误:
public void button_click(View view) {
// Create the dialog
final Dialog mDateTimeDialog = new Dialog(view.getContext());
// Inflate the root layout
final RelativeLayout mDateTimeDialogView = (RelativeLayout)getLayoutInflater()
.inflate(R.layout.datepick,false);
.....
我该如何解决这个问题?
编辑
此代码有效:
// Inflate the root layout
LayoutInflater inflater = (LayoutInflater) view.getContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
final RelativeLayout mDateTimeDialogView = (RelativeLayout) inflater.inflate(R.layout.datepick, null);
最佳答案
如果你有任何父 View get 作为 inflate 的参数。 eq: view.inflate(int resource, ViewGroup root, boolean attachToRoot);
view.inflate(int resource, parentView, false);
关于android - Fragment 类型中的方法 getLayoutInflater(Bundle) 不适用于参数 (),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16584927/