‘setHasOptionsMenu(Boolean): Unit’ is deprecated. Deprecated in Java

From the Developer documentation, this can be achieved by the following: /** * Using the addMenuProvider() API directly in your Activity **/ class ExampleActivity : ComponentActivity(R.layout.activity_example) { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // Add menu items without overriding methods in the Activity addMenuProvider(object : MenuProvider { override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) { // … Read more

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);

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