java - List fragment not appearing owing to No view found for ID error -
i'm trying launch list fragment seems working on tablets. when run app on phones app crashes. know how resolve issue? code below.
error
caused by: java.lang.illegalargumentexception: no view found id 0x7f0c0050 (com.apptacularapps.exitsexpertlondonlite:id/master_container) fragment fragmentmainlist{b76424 #1 id=0x7f0c0050} 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/list_main" 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; } }
it's because have line
transaction.replace(r.id.master_container, newfragment); and don't have layout inside activity_main.xml has same id master_container
Comments
Post a Comment