android - Error inflating ListFragment from XML file -
i building android app using fragments. in xml file 1 of fragments have 1 listfragment , 1 button, (the filteredrecipeslistfragment extending listfragment):
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <com.mycompany.myapp.gui.filteredrecipeslistfragment android:id="@+id/filtered_recipes_list_fragment" android:layout_width="match_parent" android:layout_height="wrap_content" android:focusable="true" /> <button android:id="@+id/show_recipe_filter_dialog_button" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/show_recipe_filter_dialog_button" android:onclick="showfilter" /> </linearlayout> fairly simple stuff. furthermore class filteredrecipesfragment inflate xml file looks this:
public class filteredrecipesfragment extends fragment { private filteredrecipeslistfragment mfilteredrecipeslistfragment; private button mshowrecipefilterbutton; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.filtered_recipes_fragment, container, false); mfilteredrecipeslistfragment = (filteredrecipeslistfragment) getfragmentmanager().findfragmentbyid(r.id.filtered_recipes_list_fragment); mshowrecipefilterbutton = (button) rootview.findviewbyid(r.id.show_recipe_filter_dialog_button); showrecipefilterbutton.setonclicklistener(new recipefilterbuttonlistener()); return rootview; } } should straightforward. problem @ line inflating filteredrecipeslistfragment. here nosuchmethodexception: filteredrecipeslistfragment(context, attributeset), because have not implemented constructor in filteredrecipeslistfragment class. not sure why need that, since calling super(context, attributeset) not option in fragments in views.
and heading wrong; approaching whole concept of fragments wrong in case? better practice or make more sense use listview instead of custom listfragment inside fragment? if ok using filteredrecipeslistfragment(context, attributeset) method, how should use make class inflatable?
here filteredrecipeslistfragment reference:
public class filteredrecipeslistfragment extends listfragment { private filteredrecipeslistadapter mrecipeadapter; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { mrecipeadapter = new filteredrecipeslistadapter(getactivity(), null); return super.oncreateview(inflater, container, savedinstancestate); } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); } @override public void onpause() { super.onpause(); } @override public void onlistitemclick(listview l, view v, int position, long id) { super.onlistitemclick(l, v, position, id); } }
try looking @ this.
look @ how should declare fragment in xml:
<fragment android:name="com.example.android.fragments.headlinesfragment" android:id="@+id/headlines_fragment" android:layout_width="match_parent" android:layout_height="match_parent" />
Comments
Post a Comment