1

ViewPagerExtensionsを使用しています。PagerAdapterクラスの各タブで新しいアクティビティを開始したいと思います。

現在、これはデフォルトのコードです。

@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;

}

私はそれがアンドロイドタブのために行われるように何かをしたいです:

@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);

}

これにより、エラーがスローされます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 に答える