getLayoutInflater().inflate(R.layout.backup_reminder, null) or context.getLayoutInflater().inflate(R.layout.backup_reminder, null); Not working non activity or fragment class or getLayoutInflater() not resolved.

Problem:-

getLayoutInflater().inflate(R.layout.backup_reminder, null) or context.getLayoutInflater().inflate(R.layout.backup_reminder, null); Not working non activity or fragment class or outsite activity or fragment class or getLayoutInflater() not resolved.

View mView = getLayoutInflater().inflate(R.layout.backup_reminder, null); // not working
View mView = context.getLayoutInflater().inflate(R.layout.backup_reminder, null); // not working


Solution:-
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@SuppressLint("InflateParams") View mView = inflater.inflate(R.layout.backup_reminder, null);

In My case For AlertDialog:-

ClsGlobal class // which is not activity or fragment class.
AlertDialog.Builder mAlertDialogBuilder = new AlertDialog.Builder(context);
        LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        @SuppressLint("InflateParams") View mView = inflater.inflate(R.layout.backup_reminder, null);
        final Button btn_bkp_cloud = mView.findViewById(R.id.br_backup_to_cloud);
        final Button btn_bkp_local = mView.findViewById(R.id.br_backup_to_local);
        mAlertDialogBuilder.setView(mView);
        final AlertDialog dialog = mAlertDialogBuilder.create();
        dialog.show();

        btn_bkp_cloud.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                dialog.dismiss();

            }
        });

        btn_bkp_local.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                dialog.dismiss();

             

            }
        });
------------------------------------------------ End----------------------------------------------------------


Result:-

context getlayoutinflater () not working

getlayoutinflater in non activity class

fragment layout inflate

inflate in fragment android

inflate linearlayout in fragment

layoutinflater inflater getlayoutinflater () in adapter

layoutinflater inflater activity getlayoutinflater ();


how to remove inflated layout in android

getlayoutinflater () inflate in android

attachtoroot android

android inflate layout programmatically

getlayoutinflater in fragment

cloneincontext () android

layoutinflater kotlin

layout_inflater_service


layout inflater method

android inflate layout programmatically

inflate android

inflate() in android

layoutinflater in android tutorial point

android inflate layout from xml

how to remove inflated layout in android

attachtoroot android

layoutinflater in adapter

android inflate layout into view

inflate layout dynamically android

android inflate layout from xml

inflate layout in service android

inflate layout on button click in android

how to remove inflated layout in android

inflate layout in adapter android

layoutinflater kotlin

attachtoroot android

getlayoutinflater in fragment

android inflate layout programmatically

layout_inflater_service

cloneincontext () android

layout inflater method

layoutinflater constructor

android app activity getlayoutinflater ()' on a null object reference

android fragment tutorial with example

android fragment example

android fragment example source code

fragment example in android studio

layoutinflater in android tutorial point

android fragment vs activity

static fragment android

fragment activity in android

getlayoutinflater () inflate in android

attachtoroot android

android inflate layout programmatically

layoutinflater kotlin

layoutinflater from vs getlayoutinflater

inflater in fragment

layout inflater method

layoutinflater constructor

android inflate layout programmatically

android remove view from layout programmatically

android remove child view

layoutinflater in android tutorial point

android inflate layout into view

android add view programmatically

android delete view from activity

remove view from framelayout android



Comments

Popular posts from this blog

Error:java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant). at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:240) at com.google.android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.java:215) at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:143) at com.google.android.material.internal.ThemeEnforcement.obtainStyledAttributes(ThemeEnforcement.java:78) at com.google.android.material.chip.ChipDrawable.loadFromAttributes(ChipDrawable.java:359) at com.google.android.material.chip.ChipDrawable.createFromAttributes(ChipDrawable.java:292) at com.google.android.material.chip.Chip.(Chip.java:193) at com.google.android.material.chip.Chip.(Chip.java:186) at com.google.android.material.chip.Chip.(Chip.java:182) at com.demo.nspl.restaurantlite.Navigation_Drawer.SalesFragment.getFilterChip(SalesFragment.java:158) at com.demo.nspl.restaurantlite.Navigation_Drawer.SalesFragment.lambda$onCreateView$0(SalesFragment.java:71) at com.demo.nspl.restaurantlite.Navigation_Drawer.-$$Lambda$SalesFragment$KCm-iiczjdYbpiNmaNw12gtFOoQ.onClick(lambda) at android.view.View.performClick(View.java:5268) at android.view.View$PerformClick.run(View.java:21550) at android.os.Handler.handleCallback(Handler.java:822) at android.os.Handler.dispatchMessage(Handler.java:104) at android.os.Looper.loop(Looper.java:207) at android.app.ActivityThread.main(ActivityThread.java:5811) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:681)

Configuration 'androidTestCompile' is obsolete and has been replaced with 'androidTestImplementation' and 'androidTestApi'. It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'. It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html Configuration 'androidTestApi' is obsolete and has been replaced with 'androidTestImplementation'. It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html Configuration 'testCompile' is obsolete and has been replaced with 'testImplementation' and 'testApi'. It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html Configuration 'testApi' is obsolete and has been replaced with 'testImplementation'. It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html