Reputation: 145
I'm trying to use a custom datePicker date picker
but I'm getting this error when inflating the root Layout inside a 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);
.....
How can I fix this ?
EDIT
This code works :
// Inflate the root layout
LayoutInflater inflater = (LayoutInflater) view.getContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
final RelativeLayout mDateTimeDialogView = (RelativeLayout) inflater.inflate(R.layout.datepick, null);
Upvotes: 4
Views: 4978
Reputation: 425
if you have any parent view get as a argument of inflate. eq: view.inflate(int resource, ViewGroup root, boolean attachToRoot);
view.inflate(int resource, parentView, false);
Upvotes: 2