Custom Layout for DialogFragment OnCreateView vs. OnCreateDialog

I had the same exception with the following code: public class SelectWeekDayFragment extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { return new AlertDialog.Builder(getActivity()) .setMessage(“Are you sure?”).setPositiveButton(“Ok”, null) .setNegativeButton(“No way”, null).create(); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.week_day_dialog, container, false); return view; } } You must choose … Read more

Inflate layout programmatically within another layout

You could use something like LayoutInflater inflater = LayoutInflater.from(context); //to get the MainLayout View view = inflater.inflate(container_destacado, null); … //Avoid pass null in the root it ignores spaces in the child layout View inflatedLayout= inflater.inflate(R.layout.yourLayout, (ViewGroup) view, false); containerDestacado.addView(inflatedLayout);

Problem inflating custom view for AlertDialog in DialogFragment

The first error line gives me the hint that this is related to how you are creating your dialog – not the dialog itself. Are you creating the dialog automatically (which could mean this gets called before the views are all set up) or in response to a button click? I initially had problems with … Read more

NPE while inflating layout (Attempt to invoke virtual method ‘boolean java.lang.String.equals(java.lang.Object)’ on a null object reference)

Change <view to <View, because view is not about empty view. It’s for custom view defined through class attr, like below: <view android:layout_width=”wrap_content” android:layout_height=”wrap_content” class=”com.your.package.YourCustomView” /> And you got Caused by: java.lang.NullPointerException: Attempt to invoke virtual method ‘boolean java.lang.String.equals(java.lang.Object)’ on a null object reference because of LayoutInflater tries to parse class attr: LayoutInflater source code … Read more

android.view.InflateException: Binary XML file line #12: Error inflating class

The inflate exception is not actually the problem but really comes from another deeper issue in your layout that is then wrapped in an InflateException. A common issue is an out of memory exception when trying to inflate an ImageView loading a drawable resource. If one of these resources has a high pixel resolution it … Read more