android - How to update ListFragment on Runtime -
i developing app in there 3 pan layout fragments , each fragments listfragment
. communicating between them via interface
not able update listview
new items. here code of listview
need updated:
public class subchapterslistfragment extends sherlocklistfragment { public interface onsubchapterselectlistener { public void onsubchapterselected(int position); } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); madapter = null; } @override public void onstart() { super.onstart(); if (getfragmentmanager().findfragmentbyid( r.id.sub_sub_category_fragment) != null) { getlistview().setchoicemode(listview.choice_mode_single); } } // function invoked fragment (succesffully invoked) public void updatelist(int position) { log.d("success", "" + position); // position passed int layout = build.version.sdk_int >= build.version_codes.honeycomb ? android.r.layout.simple_list_item_activated_1 : android.r.layout.simple_list_item_1; arraylist<string> items = new arraylist<string>(); // chapter instance = competitiveprogramming.chapterlist.get(position); (int = 0; < competitiveprogramming.chapterlist.get(position).subchapterlist.size(); i++) { items.add(competitiveprogramming.chapterlist.get(position).subchapterlist.get(i).subchaptertitle); } // okay till setlistadapter(new arrayadapter<string>(getsherlockactivity(), layout, items)); // not working in line , crashed } }
how update listview
in runtime?
update:
public class subchapterslistfragment extends sherlocklistfragment { onsubchapterselectlistener mcallback; public interface onsubchapterselectlistener { public void onsubchapterselected(int prev, int position); } arrayadapter<string> madapter; int mposition; @override public void onactivitycreated(bundle savedinstancestate) { super.onactivitycreated(savedinstancestate); arraylist<string> items = new arraylist<string>(); int layout = build.version.sdk_int >= build.version_codes.honeycomb ? android.r.layout.simple_list_item_activated_1 : android.r.layout.simple_list_item_1; chapter instance = competitiveprogramming.chapterlist.get(0); (int = 0; < instance.subchapterlist.size(); i++) { items.add(instance.subchapterlist.get(i).subchaptertitle); } madapter = new arrayadapter<string>(getsherlockactivity(), layout, items); setlistadapter(madapter); } @override public void onstart() { super.onstart(); if (getfragmentmanager().findfragmentbyid( r.id.sub_sub_category_fragment) != null) { getlistview().setchoicemode(listview.choice_mode_single); } } public void updatelist(int position) { mposition = position; madapter.clear(); arraylist<string> items = new arraylist<string>(); (int = 0; < competitiveprogramming.chapterlist.get(position).subchapterlist.size(); i++) { items.add(competitiveprogramming.chapterlist.get(position).subchapterlist.get(i).subchaptertitle); } madapter.notifydatasetchanged(); } @override public void onlistitemclick(listview l, view v, int position, long id) { mcallback.onsubchapterselected(mposition, position); getlistview().setitemchecked(position, true); } }
try this:
madapter.clear(); (int = 0; < competitiveprogramming.chapterlist.get(position).subchapterlist.size(); i++) { madapter.add(competitiveprogramming.chapterlist.get(position).subchapterlist.get(i).subchaptertitle); } madapter.notifydatasetchanged();
Comments
Post a Comment