When the fragment should return true from isInLayout method? In my case it returns false but I can see the fragment and isVisible and isAdded returns true.
in my activity onCreate method I'm calling 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 I want to pass the adapter to the fragment liek this:
@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 isInLayout
returns false.
When the fragment should return true from isInLayout method?
Fragment will return true when it is part of the layout defined via XML otherwise will return false. Relevant documentation part.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With