android - Replaced Fragments are still active -


i writing android app using support version of fragments (android.support.v4.app.fragment).

i have strange bug in code , dont know how fix it. when replace fragment other one, replaced 1 still active , receiving touch events. tap on location of button replaced fragment still fire onclick event.

i dont know how fix this. can me?

java code

fragment newfragment = new loginactivityregisterfragment();  ...  fragmenttransaction ft = getsupportfragmentmanager().begintransaction(); ft.settransition(fragmenttransaction.transit_fragment_fade); ft.replace(r.id.login_fragment, newfragment); ft.commit();  ... 

xml layout

...  <fragment     class="de.myapp.fragments.loginactivitymainfragment"     android:layout_height="match_parent"     android:layout_width="match_parent"     android:id="@+id/login_fragment" />  ... 

you can replace fragments in container view only. means need container (not fragment itself).

<framelayout     android:layout_height="match_parent"     android:layout_width="match_parent"     android:id="@+id/container" /> 

then can initialize adding fragment it.

fragmenttransaction ft = getsupportfragmentmanager().begintransaction(); ft.settransition(fragmenttransaction.transit_fragment_fade); ft.add(r.id.container, new loginactivitymainfragment()); ft.commit(); 

and can replace it.

fragment newfragment = new loginactivityregisterfragment(); fragmenttransaction ft = getsupportfragmentmanager().begintransaction(); ft.settransition(fragmenttransaction.transit_fragment_fade); ft.replace(r.id.container, newfragment); ft.commit(); 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -