2012-07-14 110 views
1

我正在使用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>)

回答

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每个选项卡中显示新的活动

更新

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

+0

感谢您的回复。那么计算器类将不得不以这种格式重新编码? – input 2012-07-21 21:30:52

+0

看到我更新的答案 – 2012-07-22 03:01:09

0

你是否试图夸大这些活动的布局而不是?

​​
+0

我不确定我是否理解。我想在其中一个标签中显示日历。我从这里有一个类:http://w2davids.wordpress.com/android-simple-calendar我该怎么做? – input 2012-07-15 14:28:09

+0

@input,你有没有试过膨胀simple_calendar_view xml布局文件? – yugidroid 2012-07-15 16:58:50

+0

对不起,我是新手。真的很感谢你的帮助,如果你能告诉我如何做到这一点? – input 2012-07-15 17:24:23