How to update ListFragment on Runtime
I am developing an app in which there are three pan layout with fragments
and each fragments are ListFragment. I am communicating between them via
interface successfully but I am not able to update the ListView with new
items. Here is my code of the ListView which need to be updated:
public class SubChaptersListFragment extends SherlockListFragment {
public interface OnSubChapterSelectListener {
public void onSubChapterSelected(int position);
}
@Override
public void onStart() {
super.onStart();
if (getFragmentManager().findFragmentById(
R.id.sub_sub_category_fragment) != null) {
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
}
}
// this function will be invoked from another fragment
(succesffully invoked)
public void updateList(int position) {
Log.d("success", "" + position); // position is successfully 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);
for (int i = 0; i <
CompetitiveProgramming.chapterList.get(position).subchapterList.size();
i++) {
items.add(CompetitiveProgramming.chapterList.get(position).subchapterList.get(i).subChapterTitle);
}
// everything is okay till now
setListAdapter(new
ArrayAdapter<String>(getSherlockActivity(), layout,
items)); // is not working in this line and crashed
}
}
How to update the ListView frequently in runtime?
No comments:
Post a Comment