我正在使用ViewPagerExtensions。我想在Pager Adapter類的每個選項卡中開始一個新的活動。在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;
}
我想,因爲它是爲Android標籤做什麼事:
@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>)
。
感謝您的回覆。那麼計算器類將不得不以這種格式重新編碼? – input 2012-07-21 21:30:52
看到我更新的答案 – 2012-07-22 03:01:09