Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用其他类的片段管理选项卡活动_Java_Android_Class_Android Fragments - Fatal编程技术网

Java 使用其他类的片段管理选项卡活动

Java 使用其他类的片段管理选项卡活动,java,android,class,android-fragments,Java,Android,Class,Android Fragments,我在另一个类中有一个片段,我想从我的选项卡活动(Google直接提供)启动它: 这是我的FragmentActivity中控制片段的部分,我不想要伪片段,而是我在另一个类中创建的片段 public class SectionsPagerAdapter extends FragmentPagerAdapter { public SectionsPagerAdapter(FragmentManager fm) { super(fm); } @Overrid

我在另一个类中有一个片段,我想从我的选项卡活动(Google直接提供)启动它:

这是我的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;
    }
}
这是我的片段:

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

但是它不起作用。

好的,答案很简单:

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;
}
不是一个真正的方法,我甚至不知道为什么Eclipse在创建类时给了我这个

真正的方法是:

public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    TextView textView = new TextView(context);
    textView.setText("search page");
    return textView;
}
这只是一个参数问题