java - ListFragment appearing twice on phone -
i'm seeing undesired appearance of list fragment when run app on phone emulator. on tablet emulator appears once on phone emulator appears twice. how can fix error list appear on phone emulator once?
mainactivity.java
public class mainactivity extends actionbaractivity { private boolean mtwopane; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); fragmentmainlist newfragment = new fragmentmainlist(); fragmenttransaction transaction = getsupportfragmentmanager().begintransaction(); transaction.replace(r.id.master_container, newfragment); transaction.commit(); if (findviewbyid(r.id.detail_container) != null) { mtwopane = true; } } } activity_main.xml
<fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/master_container" android:name="com.apptacularapps.exitsexpertlondonlite.fragmentmainlist" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".fragmentmainlist" tools:layout="@android:layout/list_content"/> activity_main.xml (sw600dp)
<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:orientation="horizontal" android:showdividers="middle" tools:context=".mainactivity" > <relativelayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:id="@+id/master_container"/> <framelayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="3" android:id="@+id/detail_container"/> </linearlayout> fragmentmainlist.java
public class fragmentmainlist extends android.support.v4.app.fragment { listview list_main; string[] listcontent = { "item 1", "item 2", "item 3" }; private boolean mtwopane; public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate){ view v = inflater.inflate(r.layout.fragment_main_list, container, false); list_main = (listview)v.findviewbyid(r.id.list_main); arrayadapter<string> adapter = new arrayadapter<string>(getactivity(),android.r.layout.simple_list_item_1,listcontent); list_main.setadapter(adapter); return v; } }
please move logic add fragment inside if loop have.
Comments
Post a Comment