android - ViewPager and fragment replacement. Again -
i have simple list/detail app in dual pane mode: left side - listfragment, right side - viewpager. here layout:
<linearlayout 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" android:baselinealigned="false" > <linearlayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" > <fragment android:id="@+id/site_list" android:name="com.example.fragmentviewpager.listfragment" android:layout_width="match_parent" android:layout_height="match_parent" /> </linearlayout> <linearlayout android:id="@+id/viewpager" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="3" > <android.support.v4.view.viewpager android:id="@+id/pager" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </linearlayout> </linearlayout>
everything works fine: when click on list item, detailed information shown in viewpager. viewpager consist 2 simple fragments in tabs.viewpager uses fragmentstatepageradapter create fragments.
fragments layout:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/relativelayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <textview android:id="@+id/title" android:layout_width="match_parent" android:layout_height="match_parent" android:text="test" android:textappearance="?android:attr/textappearancelarge" android:clickable="true" > </textview> <textview android:id="@+id/tvpage" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:textappearance="?android:attr/textappearancelarge" > </textview> </relativelayout>
now, want show new fragment instead of first fragment when click on textview id=title
in first fragment. have listener on textview:
title.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { fragment3 fragment3 = new fragment3(); fragmenttransaction transaction = getchildfragmentmanager() .begintransaction(); transaction.addtobackstack(null); transaction.replace(r.id.some_id, fragment3).commit(); } });
but have no idea, have write instead some_id
... , in general, can fragment replace itself? how replace fragment???
if need additional code - tell me.
Comments
Post a Comment