如何使用page_two启动活动

时间:2016-12-01 21:42:32

标签: java android android-activity

如何使用page_ two实现Activity?我能做什么?

以下是一个例子:This image

到目前为止,我的活动代码如下所示:

ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    viewPager.setAdapter(new CustomPagerAdapter(this));

CustomPagerAdapter.java

public class CustomPagerAdapter extends PagerAdapter {

private Context mContext;

public CustomPagerAdapter(Context context) {
    mContext = context;
}

@Override
public Object instantiateItem(ViewGroup collection, int position) {
    ModelObject modelObject = ModelObject.values()[position];
    LayoutInflater inflater = LayoutInflater.from(mContext);

    ViewGroup layout = (ViewGroup) inflater.inflate(modelObject.getLayoutResId(), collection, false);
    collection.addView(layout);
    return layout;
}

@Override
public void destroyItem(ViewGroup collection, int position, Object view) {
    collection.removeView((View) view);
}

@Override
public int getCount() {
    return ModelObject.values().length;
}

@Override
public boolean isViewFromObject(View view, Object object) {
    return view == object;
}

@Override
public CharSequence getPageTitle(int position) {
    ModelObject customPagerEnum = ModelObject.values()[position];
    return mContext.getString(customPagerEnum.getTitleResId());
}
}

和ModelObject.java

 public enum ModelObject {


BLUE(R.string.blue, R.layout.page_one),
GREEN(R.string.green, R.layout.page_two),
RED(R.string.blue, R.layout.page_tree);

private int mTitleResId;
private int mLayoutResId;


ModelObject(int titleResId, int layoutResId) {
    mTitleResId = titleResId;
    mLayoutResId = layoutResId;
}

public int getTitleResId() {
    return mTitleResId;
}

public int getLayoutResId() {
    return mLayoutResId;
}

}

我该如何解决这个问题? 我改了名单,但我没有; 怎么样?

0 个答案:

没有答案