0

I am creating a survey app based on WizarDroid. I am using a ViewPager and the questions are loaded dynamically in each fragment in the ViewPager.

The ViewPager creates 3 fragments: "Pre", "Current" and "Next".

I am having a problem with the "Next" fragment because my last fragment is a ListFragment (AnswerReviewList) so the list cannot update the last question and answer because it is already created.

Is it possible to refresh the list (ReviewListfragment) from a ViewPager listener method?

@Override
public void onPageSelected(int position) {}

Please ask if you don't understand my question.

ReviewListFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {

    super.onActivityCreated(savedInstanceState);
    Log.i("############################ last fragment ",
            "onActivityCreated");
    queArrListVO = ((EventSurveyActivity) getActivity()).surveyQuetionVOList;
    adptrReviewQuestion = new SurveysReviewBaseAdapter(
            getSherlockActivity(), queArrListVO);
    getListView().setAdapter(adptrReviewQuestion);
    getListView().setOnItemClickListener(this);

    setEmptyText(" :) ");
    setListShown(true);
}
MilapTank
  • 9,988
  • 7
  • 38
  • 53

1 Answers1

1

If your SurveysReviewBaseAdapter extends from BaseAdapter (which I'll assume given the name of the class), you can use BaseAdapter.notifyDatasetChanged to reload the ListAdapter with the new data in, for example, onResume.

Menno
  • 1,133
  • 9
  • 14
  • thanks for answer problem is that i can not do like this because fragment is already created in ViewPager and onResume() of ListFragment called before new data i fill data in Fragment – MilapTank Feb 24 '14 at 09:10
  • Can you access the adapter (e.g., using [`Fragment.getListAdapter()`](http://developer.android.com/reference/android/app/ListFragment.html#getListAdapter())) after you "fill the data in Fragment"? Because you could just call it then... – Menno Feb 24 '14 at 10:23
  • yes i can do this but i am doing that than i get nullPointerException because SurveysReviewBaseAdapter is my custom adapter http://pastie.org/private/cttrybhoypqlc1i8po7aig#5-8 see code in both method i got same error – MilapTank Feb 24 '14 at 10:49
  • Forget what I said about notifyDatasetChanged. Can you use [`viewPager.setOffscreenPageLimit(0)`](http://developer.android.com/reference/android/support/v4/view/ViewPager.html#setOffscreenPageLimit(int)) and see if that works? – Menno Feb 24 '14 at 11:00
  • its still create next fragment i have create Log when i am on getCount()-1 page at that time getCount() number page all methods are called – MilapTank Feb 24 '14 at 11:12
  • hey @menno i have tried as you say but see this http://stackoverflow.com/questions/10073214/viewpager-setoffscreenpagelimit0-doesnt-work-as-expected – MilapTank Feb 26 '14 at 13:55