I'm using support package v4.
mFragmentManager = getSupportFragmentManager();
FragmentTransaction ft = mFragmentManager.beginTransaction();
ft.add(R.id.fragContainer1, new ModelListFragment(), FRAG_MODEL_LIST);
ft.add(R.id.fragContainer2, new TrimListFragment(), FRAG_TRIM_LIST);
ft.commit();
Fragment fragment = mFragmentManager.findFragmentByTag(
MainActivity.FRAG_MODEL_LIST);
Log.d("MY", "found fragment: " + (fragment != null));
Always returns "found fragment: false". I'm missing something really obvious here, what is it?
As you can see in doc:
The commit does not happen immediately; it will be scheduled as work on the main thread to be done the next time that thread is ready.
that's why you doesn't see your fragment just after commit().
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