The Green Foxx The Green Foxx - 2 years ago 95
Android Question

Fragment not showing when add() method is called

here is the declarations:

FragmentManager fr = getFragmentManager();
FragmentTransaction ft = fr.beginTransaction();
Fragment myFragment = new defaultFragment();
ft.add(, myFragment);

and here is the

public void startFragment(View v){
newFragment = new nextFragment();

execute method :

public void execute() {
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.add(, newFragment);

i cant the problem but when i click the button that triggers the
startFragment(View v)
method, nothing happens, the fragment is not replaced by the fragment that i want to add on the stack. I think the problem has something to do with this line
transaction.add(, newFragment);
help please thanks :)

Answer Source

Try adding the fragment to FrameLayout instead. I was not able to add it to LinearLayout, but I changed it to FrameLayout and it worked.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download