Android: can't load in a detail fragment in master detail -
i have app works on handheld device , want work on tablet using master/detail flow. have informationfragment
shown when click on item in listview
. app works on handheld device, on tablet exception there no view found two_pane_information_container
. here code:
public class mainactivity extends fragmentactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); twopane = getresources().getboolean(r.bool.istablet); setcontentview(r.layout.main_layout); // setting navigation view , listfragment etc. } public static class informationlistfragment extends listfragment { @override public void onlistitemclick(listview l, view v, int position, long id) { info o = (info) getlistadapter().getitem(position); bundle b = new bundle(); b.putparcelable("info", o); if (twopane) { // load fragment right of list // part causing problems android.support.v4.app.fragmenttransaction ft =getfragmentmanager().begintransaction(); informationfragment ia = new informationfragment(); ia.setarguments(b); ft.replace(r.id.two_pane_information_container, ia); ft.commit(); } else { // activity displays inforrmationfragment // works intent = new intent(getactivity(), informationactivity.class); i.putextra("info", b); startactivity(i); } } }
res/layout/fragment_main.xml
<android.support.v4.widget.drawerlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/table_background" > <!-- main content view --> <android.support.v4.view.viewpager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent" > </android.support.v4.view.viewpager> <!-- navigation drawer --> <listview android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" android:background="@android:color/background_dark" android:choicemode="singlechoice" android:divider="@android:color/transparent" android:dividerheight="1dip" /> </android.support.v4.widget.drawerlayout>
res/layout/main_twopane.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" > <include android:layout_width="400dp" layout="@layout/fragment_main" /> <linearlayout android:id="@+id/two_pane_information_container" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" > </linearlayout> </linearlayout>
res/values/layouts.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <bool name="istablet">false</bool> <item name="main_layout" type="layout">@layout/fragment_main</item> </resources>
res/values-large/layouts.xml , res/values-sw600dp/layouts.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <bool name="istablet">true</bool> <item name="main" type="layout">@layout/main_twopane</item> </resources>
your layout name in final 2 xml files differs.
<item name="main" type="layout">
should be
<item name="main_layout" type="layout">
Comments
Post a Comment