I have A fragment in another class and i want to launch it from my tab activity (which Google provide directly):
Here’s the part of my FragmentActivity that control fragments, i don’t want the dummy one but the one i created in another class
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;
}
}
And here is my 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;
}
}
But it doesn’t work.
Okay, the answer is simple :
is not a real method, i don’t even know why Eclipse gave me this when i created the class.
The real method is :
This is just a problem of parameters.