android - How to show second fragment from first fragment with in a single activity -


i developing simple android app tablets , using android 4.0. application have main screen follow:

enter image description here

oncreate() of main activity adding fragment in main.xml using following code:

fragmenttransaction ft = getfragmentmanager().begintransaction(); fragment imagefragment = new imagefragment(); ft.replace(r.id.fragment_container, imagefragment); ft.settransition(fragmenttransaction.transit_fragment_fade); ft.addtobackstack(null); ft.commit(); 

this fragment have image view clickable. want when user click on image view fragment (fragment b) should call , replace image view. fragment b have videoview play video.

so second screen should follow:

enter image description here

my problem not gettting "how call second fragment first 1 in main screen activity?"

i can use different activities not want , want run using fragments.

please guide me.

this simplest way:

1) inside youractivitycreate method:

public void gotosecondfragment(){}     fragmenttransaction ft = getfragmentmanager().begintransaction();     fragment secondfragment = new secondfragment();     ft.replace(r.id.fragment_container, secondfragment);     ft.settransition(fragmenttransaction.transit_fragment_fade);     ft.addtobackstack(null);     ft.commit(); } 

2) in first fragment, when want replace it, call:

youractivity activity = (youractivity) getactivity(); activity.gotosecondfragment(); 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -