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

Android Studio 3.5 or above usb device not detected in Android Studio or Unable to detect adb version, exit value: 0xc0000135. ADB depends on the Windows Universal C Runtime, which is usually installed by default via Windows Update. You may need to manually fetch and install the runtime package here: https://support.microsoft.com/en-ca/help/2999226/update-for-universal-c-runtime-in-windows

Lint found fatal errors while assembling a release target.

ViewModelProviders.of(this) is deprecated what to use instead ViewModelProviders.of(this) OR if you don't want to use ViewmodelFactory OR ViewModelProviders error.