求androidViewpager+fragment动态添加删除比较好的demo
2017-12-26 · 知道合伙人数码行家
知道合伙人数码行家
向TA提问 私信TA
package com.yang.Adapter;
import java.util.ArrayList;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
public class MyFragmentPagerAdapter extends FragmentStatePagerAdapter {
private static final String TAG = "MyFragmentPagerAdapter";
// private ArrayList<OpilistItem> lists;
private ArrayList<Fragment> mList;
private Context mContext;
public MyFragmentPagerAdapter(FragmentManager fm, Context context) {
super(fm);
this.mContext = context;
mList = new ArrayList<Fragment>();
}
public void setLists(ArrayList<Fragment> lists) {
this.mList = lists;
}
public void UpdateList(ArrayList<Fragment> arrayList) {
this.mList.clear();
this.mList.addAll(arrayList);
notifyDataSetChanged();
}
@Override
public Fragment getItem(int arg0) {
// Fragment ft = null;
//
// ft = new DateShow(mContext);
// for (int i = 0; i < lists.get(arg0).openplayitem.size(); i++) {
// Log.i(TAG,
// "arg0=" + arg0 + "name="
// + lists.get(arg0).openplayitem.get(i).moviename);
// }
//
// Bundle args = new Bundle();
// args.putSerializable("date_title", lists.get(arg0).openplayitem);
// ft.setArguments(args);
// return ft;
return mList.get(arg0);
}
@Override
public int getCount() {
return mList.size();
}
@Override
public int getItemPosition(Object object) {
// TODO Auto-generated method stub
return PagerAdapter.POSITION_NONE;
}
}