The isInLayout snippet returns false

When should a fragment return true from the isInLayout method? In my case, it returns false, but I see a fragment, and isVisible and isAdded returns true.

in my activity onCreate method I call this:

FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
FragEventList listFrag = new FragEventList();
transaction.replace(R.id.fragment_container_1, listFrag, "list");
transaction.commit();

and this is the layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:baselineAligned="false"
    android:orientation="horizontal"
    tools:context=".MainActivity" >

    <FrameLayout
        android:id="@+id/fragment_container_1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </FrameLayout>

</LinearLayout>

later, when Loader returns the data that I want to pass to the adapter in the liek fragment, this is:

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    Log.i(TAG, "onLoadFinished(Loader<Cursor> loader, Cursor data)");

    Log.i(TAG, "fragment="+getSupportFragmentManager().findFragmentByTag("list"));

    if (mAdapter != null && data != null) {
        mAdapter.swapCursor(data);

        FragEventList fragment = (FragEventList) getSupportFragmentManager().findFragmentByTag("list");

        if(fragment != null){
            Log.i(TAG, "in layout="+fragment.isInLayout());
            Log.i(TAG, "is added="+fragment.isAdded());
            Log.i(TAG, "is visible="+fragment.isVisible());
        }

        if(fragment != null && fragment.isInLayout())
        {
            fragment.setAdapter(mAdapter);
        }

    } else {
        Log.v(TAG, "onLoadFinished: mAdapter is null");
        onLoaderReset(null);
    }

}

but isInLayoutreturns false.

+4
source share
1 answer

When should a fragment return true from the isInLayout method?

A fragment will return true when it is part of a layout defined through XML, otherwise it will return false. Relevant documentation.

+8
source

All Articles