java - setting up multiple buttons in fragment -
i have fragment so
public class pagesfragment extends fragment { public pagesfragment(){} public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view v = inflater.inflate(r.layout.section, container, false); return v; }} and wanted setup 6 buttons open 6 corresponding xml layouts. if there way out setting 6 different activities love know.
the xml:
<scrollview android:layout_width="wrap_content" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/scrollview" android:background="#ffffff" android:clickable="true"> <relativelayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff"> <imagebutton android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/art" android:scaletype="fitcenter" android:adjustviewbounds="true" android:src="@drawable/art" android:layout_gravity="center_horizontal|bottom" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:background="#ffffff" /> <imagebutton android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/ext" android:scaletype="fitcenter" android:adjustviewbounds="true" android:src="@drawable/ext" android:layout_below="@+id/art" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:background="#ffffff"/> <imagebutton android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/inter" android:scaletype="fitcenter" android:adjustviewbounds="true" android:src="@drawable/inter" android:layout_below="@+id/ext" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:background="#ffffff"/> <imagebutton android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/sport" android:scaletype="fitcenter" android:adjustviewbounds="true" android:src="@drawable/sport1" android:layout_below="@+id/inter" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:background="#ffffff"/> <imagebutton android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/opp" android:scaletype="fitcenter" android:adjustviewbounds="true" android:src="@drawable/opp" android:layout_below="@+id/sport" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:background="#ffffff"/> <imagebutton android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/muse" android:scaletype="fitcenter" android:adjustviewbounds="true" android:src="@drawable/muse" android:layout_below="@+id/opp" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:background="#ffffff"/> </relativelayout> </scrollview> thankyou in advanced.
fragments it's way go. create activity (exampleactivity) layout contains framelayout (id=example_id) replaced dynamically fragment.
//inner xml of example activity layout <framelayout android:id="@+id/example_id" android:layout_width="match_parent"/> when launching intent button exampleactivity pass info fragment want use (maybe string use in factory can instantiate correct fragment).then on activity:
fragment fragment; //choose fragment intent data fragment = createfragmentfromintent(intent); fragmentmanager fragmentmanager = getchildfragmentmanager(); fragmenttransaction fragmenttransaction = fragmentmanager.begintransaction(); fragmenttransaction.replace(example_id, fragment); fragmenttransaction.commitallowingstateloss(); hope helps.
Comments
Post a Comment