Umesh Joshi
Umesh Joshi

Reputation: 13

I initialize fragment properly but it is not showing up after transaction

My code is as follows:-

FragmentManager fragmentManager = getFragmentManager(); 
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 
fragmentTransaction.replace(R.id.fragment_container, mFeedFragment); 
fragmentTransaction.addToBackStack(null); 
fragmentTransaction.commit();

Upvotes: 1

Views: 75

Answers (3)

Nandu Dharmapalan
Nandu Dharmapalan

Reputation: 496

1) You may be giving wrong handle to the FrameLayout in the view for your activity.

2) You may be mixing Activity, AppCompatActivity, getFragmentManager and getSupportFragmentManager. If your activity is inheriting Activity use getFragmentManager, or if it is using AppCompatActivity use getSupportFragmentManager.

Upvotes: 0

Sandeep Dhull
Sandeep Dhull

Reputation: 1648

Please start by following the best practices, like using Fragment from Support package and using getSupportFragmentManager() instead of getFragmentManager()

Take one step at a time. The above piece of is insufficient for me to provide more information than this.

Upvotes: 0

Fazal
Fazal

Reputation: 122

This is bit weird but it works.

just add android:background="#FFFFFF" attribute to your root layout of the fragment and it will show properly. been there done that.

Upvotes: 1

Related Questions