如何在viewpager android中动态更新片段

时间:2016-04-09 10:36:50

标签: android android-viewpager fragment

我正在处理一个包含动态页面的应用程序,因此我已经使用了viewpager.I创建了一个动态创建的片段,在该片段中,我在成功响应后调用webservice我正在刷新数据,但片段没有更新。我正在使用StatePagerAdapter。

代码:

public class CustomPagerAdapter extends FragmentStatePagerAdapter
{
    private ArrayList<InstituteVO> _instituteList;
    private ArrayList<CourseItemVO> _courses;

    public CustomPagerAdapter(FragmentManager fm, ArrayList<InstituteVO> instituteList)
    {
        super(fm);
        _instituteList = instituteList;
        _courses=new ArrayList<>();
    }

    @Override
    public Fragment getItem(int position)
    {
        PagerItemFragment fragment = new PagerItemFragment();
        fragment.setItemInfo(_instituteList.get(position), this);
       // fragment.setCourses(_courses);
        return fragment;
    }


    @Override
    public int getCount()
    {
        return _instituteList.size();
    }
    public int getItemPosition(Object item) {

        return super.getItemPosition(item);

    }

public class PagerItemFragment extends BaseFragment implements OnWebServiceResponseListener,View.OnClickListener
{
    private RecyclerView _courseView;
    private CourseCustomRecycleAdapter _adapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        View view = inflater.inflate(R.layout.institute_pager_layout, null);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState)
    {
        super.onViewCreated(view, savedInstanceState);
        setData();
    }

    private void setData()
    {

        callDataService(_item);
    }

    private void callDataService(String slug)
    {

        WebServiceController.getInstance().serviceGET(this, new InstituteProcessor(), url, AppConstants.METHOD_GET, slug);
    }




    @Override
    public void onWebServiceResponseSuccess(OnWebServiceDataProcessListener response)
    {
        if (response != null && response instanceof InstituteProcessor)
        {
            _adapter.setData(((InstituteProcessor)response).getInstituteVO().getCourses());
        }

    }

   }

0 个答案:

没有答案