android - How do i add two listfragment in my app -


i have app displays first list using below code. how display on more list on click of list item below code. please me example code.

public class mylistfragment1 extends listfragment {      string[] videosetup ={             "properties",              "color control",              "tint",              "3d depth",             "3d format",              "dynamic backlight",              "mode",              "cache id",      };      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         listadapter mylistadapter = new arrayadapter<string>(                 getactivity(),                 android.r.layout.simple_list_item_1,                 videosetup);         setlistadapter(mylistadapter);     }      @override     public view oncreateview(layoutinflater inflater, viewgroup container,             bundle savedinstancestate) {         return inflater.inflate(r.layout.listfragment1, container, false);     }      @override     public void onlistitemclick(listview l, view v, int position, long id) {         // todo auto-generated method stub         toast.maketext(                 getactivity(),                  getlistview().getitematposition(position).tostring(),                  toast.length_long).show();         fragment2 frag = (fragment2) getfragmentmanager().findfragmentbyid(r.id.fragment2);     }     } 

i not sure of doing this. new android.

first of must write second listfragment. similarly.

then, in onlistitemclick() method of first fragment can write this:

fragment2 frag = (fragment2) getfragmentmanager().findfragmentbyid(r.id.fragment2);  activity.getfragmentmanager()                     .begintransaction()                     .replace(r.id.fragment_container, frag)                     .addtobackstack(null)                     .commit(); 

this fragment container - /res/layout/activity_main.xml. empty. bind mainactivity.class setcontentview(r.layout.activity_main):

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"                 xmlns:tools="http://schemas.android.com/tools"                 android:layout_width="match_parent"                 android:layout_height="match_parent"                 tools:context=".mainactivity"                 android:background="#000000"                 android:id="@+id/fragment_container"> </relativelayout> 

after have add new first fragment on fragment container described above.

then, in onlistitemclick(...) method of first fragment have create new second fragment , replace first.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -