1

I'm using ViewPagerExtensions. I would like to start a new activity in each tab in the Pager Adapter class.

Right now this is the default code:

@Override
public Object instantiateItem(ViewGroup container, int position) {

    RelativeLayout v = new RelativeLayout(mContext);

    TextView t = new TextView(mContext);
    t.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.FILL_PARENT));
    t.setText(mData[position]);
    t.setTextSize(30);
    t.setGravity(Gravity.CENTER);

    v.addView(t);

    ((ViewPager) container).addView(v, 0);

    return v;

}

I would like to do something as it is done for the android tabs:

@Override
public Object instantiateItem(View container, int position) {

    // Create an Intent to launch an Activity for the tab (to be reused)
        intent = new Intent().setClass(this, NewActivity.class);

}

This throws the error: The method setClass(Context, Class<?>) in the type Intent is not applicable for the arguments (PagerAdapter, Class<NewActivity>).

4

2 回答 2

2

恐怕你做不到。

如果您想要每个页面的不同布局:

View parent_view = null;

    if (position == 0) {
        parent_view = getViewForPageOne();

    } else if (position == 1) {
        parent_view = getViewForPageTwo();

    .........

    ((ViewPager) collection).addView(parent_view, 0);
    return parent_view;

}

private View getViewForPageOne(){
    View v = getLayoutInflater().inflate(R.layout.layout_page_one, null);
     TextView whatText =(TextView) v.findViewById(R.id.idOfTextView);
     whatText.setText("Page One");
     ....
     ....

     return v;
}

我认为您无法使用 ViewPagerExtensions 在每个选项卡中显示新活动

更新

如果你想开始新的活动。您可以使用ActionBarSherlock

于 2012-07-21T14:34:45.363 回答
0

您是否尝试过夸大这些活动的布局而不是?

@Override
public Object instantiateItem(View collection, int position) {
    View layout = inflater.inflate(R.layout.activity_layout, null);

    /** Find your layout Views. */
    TextView text= (TextView) layout.findViewById(R.id.any_id);

    // Set some values to your Views.

    ((ViewPager) collection).addView(layout);

    return layout;
}
于 2012-07-14T19:15:27.773 回答