我在另一个类中有一个片段,我想从我的标签活动中启动它(谷歌直接提供):
这是我的 FragmentActivity 中控制片段的部分,我不想要虚拟的,而是我在另一个类中创建的
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a DummySectionFragment (defined as a static inner class
// below) with the page number as its lone argument.
// Here is my fragment
Fragment fragment = new MyFragment();
return fragment;
}
@Override
public int getCount() {
// Show 3 total pages.
return 3;
}
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return getString(R.string.title_section1).toUpperCase();
case 1:
return getString(R.string.title_section2).toUpperCase();
case 2:
return getString(R.string.title_section3).toUpperCase();
}
return null;
}
}
这是我的 MyFragment :
public class MyFragment extends Fragment{
public Search() {
// TODO Auto-generated constructor stub
}
public View onCreateView(String name, Context context, AttributeSet attrs) {
// TODO Auto-generated method stub
TextView textView = new TextView(context);
textView.setText("search page");
return textView;
}
}
但它不起作用。