import android.content.Context;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import java.util.ArrayList;
import java.util.List;
import soexample.umeng.com.liujin20181022.R;
import soexample.umeng.com.liujin20181022.activity.MainActivity;
import soexample.umeng.com.liujin20181022.fragment.Fragment_one;
import soexample.umeng.com.liujin20181022.fragment.Fragment_two;
import soexample.umeng.com.liujin20181022.mvp.view.AppDelegate;
/*
*日期:2018/10/23
**/public class MainActivityPresenter extends AppDelegate {
private List<Fragment> mList;
private String mTitle[] = {
"列表",
"购物车"
};
@Override
public int getLayoutId() {
return R.layout.activity_main;
}
private Context context;
@Override
public void getContext(Context context) {
super.getContext(context);
this.context=context;
}
@Override
public void initData() {
super.initData();
ViewPager vp = get(R.id.viewpager);
TabLayout tb = get(R.id.tablayout);
mList = new ArrayList<Fragment>();
for (int i=0;i<mTitle.length;i++){
mList.add(new Fragment_one());
mList.add(new Fragment_two());
}
MyApdater myApdater = new MyApdater(((MainActivity) context).getSupportFragmentManager());
vp.setAdapter(myApdater);
tb.setupWithViewPager(vp);
//Toast.makeText(context,"ds",Toast.LENGTH_SHORT).show();
}
class MyApdater extends FragmentPagerAdapter{
public MyApdater(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int i) {
return mList.get(i);
}
@Override
public int getCount() {
return mTitle.length;
}
@Nullable
@Override
public CharSequence getPageTitle(int position) {
return mTitle[position];
}
}
}
在这里插入代码片