This is will run fragment in fragment that use viewpageAdapter.I want to pass data from fragment to tablayout fragment. i have try any method and still crash. i just want to passs once data to fragment in the tablayout.
First fragment. this line i want pass to tablayout fragment:-
specItem = getArguments().getString("spec_item");
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
imageUrl = getArguments().getString("image_url");
priceItem = getArguments().getString("price_item");
specItem = getArguments().getString("spec_item");
}
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_view_details_item, container, false);
textPrice = (TextView) rootView.findViewById(R.id.textPrice);
image_Details = (ImageView) rootView.findViewById(R.id.image_Detail);
tabLayout = (TabLayout) rootView.findViewById(R.id.tablayout_id);
viewPager = (ViewPager) rootView.findViewById(R.id.viewpage_id);
textPrice.setText(priceItem);
Picasso.get().load(imageUrl).into(image_Details);
ViewPageAdapter adapter = new ViewPageAdapter(getActivity().getSupportFragmentManager());
adapter.AddFragment(new FragmentSpecifications(), "Specification");
adapter.AddFragment(new FragmentReview(), "Review");
viewPager.setAdapter(adapter);
tabLayout.setupWithViewPager(viewPager);
return rootView;
}
Second fragment in tablayout, i dont know how to recieve:-
View rootView;
TextView textSpec;
String specItem;
public FragmentSpecifications() {
}
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_specification, container, false);
textSpec = (TextView) rootView.findViewById(R.id.textviewspec);
textSpec.setText();
return rootView;
}
Inside your FragmentSpecifications create a instance of the Fragment to send data to it, like this:
public static FragmentSpecifications newInstance(String priceItem) {
Bundle args = new Bundle();
args.putString("priceItem", priceItem);
FragmentSpecifications fragment = new FragmentSpecifications();
fragment.setArguments(args);
return fragment;
}
After that in same FragmentSpecifications override onCreate method and get value:
private String priceItem;
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null)
priceItem = getArguments().getString("priceItem");
}
And finally when you add FragmentSpecifications do adapter pass the value:
adapter.AddFragment(FragmentSpecifications.newInstance(priceItem), "Specification");
Related
I want to be able to click a button on my settings fragment, which will change an image on another fragment called home fragment. My app keeps crashing once i click the button and im not sure why.
Settings Fragment :
public class SettingsFragment extends Fragment {
public Button button;
public ImageView Torso;
public ImageView ShopGreenTorso;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
button = (Button) getView().findViewById(R.id.button1);
Torso = (ImageView) getView().findViewById(R.id.Torso);
ShopGreenTorso= (ImageView) getView().findViewById(R.id.ShopGreenTorso);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(getActivity(), "Purchased", Toast.LENGTH_SHORT).show();
Intent i = new Intent(SettingsFragment.this.getActivity(), AvatarFragment.class);
//i.putExtra("resID", R.drawable.torso2green);
Bundle b= new Bundle();
b.putInt("resID", R.drawable.torso2green);
SettingsFragment.this.setArguments(b);
//setArguments(bundle);
startActivity(i);
}
});
}
Avatar Fragment:
public class AvatarFragment extends Fragment {
public ImageView IV;
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState)
{
View rootView = inflater.inflate(R.layout.fragment_avatar, container, false);
// init image view
IV = (ImageView) rootView.findViewById( R.id.Torso );
// getting extras
//Bundle bundle = getActivity().getIntent().getExtras();
// Bundle bundle=getArguments();
Bundle b=getArguments();
if(b!= null)
{
int resid = b.getInt("resID");
IV.setBackgroundResource(resid);
}
return rootView;
}
}
I believe the error is coming from IV.setImageResource(resid) but im not entirely sure, any help would be much appreciated.
It's hard to tell without seeing the exception, but it might be because Bundle mappings are case-sensitive.
Your SettingsFragment uses "ResId", but your HomeFragment is expecting "resID". If no mapping is found in the Bundle, you'll be given the default value of 0 for resID. It's possible that you're crashing when calling IV.setImageResource(0);.
Your image implementation in code is wrong, you need to init your image view like this :
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState)
{
View rootView = inflater.inflate(R.layout.fragment_avatar, container, false);
// init image view
IV = (ImageView) rootView.findViewById( R.id.Torso );
// getting extras
Bundle bundle = getActivity().getIntent().getExtras();
if(bundle!= null)
{
int resid = bundle.getInt("resId");
IV.setImageResource(resid);
}
return rootView;
}
Don't pass value from Fragment to Fragment directly.
You should use setArguments from SettingsFragment and getArguments in HomeFragment
I have two fragments ListNav and SwipeNav in Navigation Drawer. ListNav shows list view of data from String array. SwipeNav shows data as swipe views of the same data from string array.
I am using single fragment for viewpager swipe views multiple tabs.
My problem is :
When I click on B in List View, it shows A in SwipeNav,
When I click on C in List View, it shows A in SwipeNav,
When I click on D in List View, it shows A in SwipeNav,
When I click on E in List View, it shows A in SwipeNav,
I want to get result:
If I click on B in List View, it will show B in SwipeNav,
If I click on C in List View, it will show C in SwipeNav,
If I click on D in List View, it will show D in SwipeNav
String Array:
<string-array name="tab_titles">
<item>A</item>
<item>B</item>
<item>C</item>
<item>D</item>
<item>E</item>
<item>F</item>
<item>G</item>
<item>H</item>
<item>I</item>
........
</string-array>
I ListNav I use below to replace to SwipeNav with OnItemClickListener:
ListNav:
public class ListNav extends Fragment {
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
//returning our layout file
//change R.layout.yourlayoutfilename for each of your fragments
return inflater.inflate(R.layout.nav_lis_layout, container, false);
}
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
FragmentManager fm=getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.add(R.id.fragment12, new ListNavAdapter());
ft.commit();
ListNavAdapter:
public class ListNavAdapter extends ListFragment {
#Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.nav_list_layout, container, false);
return view;
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
ArrayAdapter adapter = ArrayAdapter.createFromResource(getActivity(),
R.array.tab_titles, android.R.layout.simple_list_item_1);
setListAdapter(adapter);
getListView().setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
String[] tabTitlesArray = getContext().getResources().getStringArray(R.array.tab_titles);
Bundle bundle = new Bundle();
bundle.putString("tab_titles", tabTitlesArray[i].toString());
SwipeNav fragobj = new SwipeNav();
fragobj.setArguments(bundle);
FragmentManager fm=getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(((ViewGroup)(getView().getParent())).getId(), fragobj);
ft.addToBackStack(null);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.commit();
}
});
}
In SwipeNav:
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
if (getArguments() != null && !getArguments().isEmpty()) {
Bundle bundle = this.getArguments();
String myInt = bundle.getString("tab_titles");
}
return inflater.inflate(R.layout.nav_swipe, container, false);
}
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
myPagerAdapter = new MyPagerAdapter(getChildFragmentManager(),getContext());
viewPager = (ViewPager) view.findViewById(R.id.pager);
viewPager.setAdapter(myPagerAdapter);
}
This is MyPagerAdapter:
public class MyPagerAdapter extends FragmentStatePagerAdapter {
private Context context;
private String[] tabTitlesArray = null;
public MyPagerAdapter(FragmentManager fm, Context context) {
super(fm);
tabTitlesArray = context.getResources().getStringArray(R.array.tab_titles);
this.context= context;
}
#Override
public Fragment getItem(int i) {
Fragment fragment = new AFragment();
Bundle args = new Bundle();
args.putString(AFragment.ARG_OBJECT, tabTitlesArray[i]);
fragment.setArguments(args);
return fragment;
}
#Override
public int getCount() {
return tabTitlesArray.length;
}
#Override
public CharSequence getPageTitle(int position) {
return "OBJECT " + (position + 1);
}
}
Single fragment for tabbed activity AFragment:
public class AFragment extends Fragment {
public static final String ARG_OBJECT = "object";
public AFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// The last two arguments ensure LayoutParams are inflated
// properly.
View rootView = inflater.inflate(R.layout.fragment_a, container, false);
Bundle args = getArguments();
((TextView) rootView.findViewById(R.id.text1)).setText(args.getString(ARG_OBJECT));
return rootView;
}
nav_lis_layout:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragment12"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
nav_list_layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
I searched all answers in Stackoverflow. But fail to solve my problem why particular item click not showing same item to the next fragment.
I need your help plz.
you should not put into string commas
"tabTitlesArray[i]"
try with
""+tabTitlesArray[i]
When I click on B in List View, it shows A in SwipeNav,
The problem is because you are sending the same object but with different keys.
What you have to do is, in your onClick get the position of your adapter and put it to your bundle
bundle.putString("tab_titles", tabTitlesArray[i].toString());
Then you get the value using String myString = bundle.getString("tab_titles");
And then when you create the adapter, you can send the String via parameter and put the text in your adapter, anyways the code is a mess... It's very hard to understand.
In your SwipeNav, after you setup the ViewPager, you have not use viewPager.setCurrentItem() to change to your desired page. Since setCurrentItem() needs an integer argument, so the clicked position in the list needs to pass from ListNavAdapter to SwipeNav.
ListNavAdapter.java:
public class ListNavAdapter extends ListFragment {
#Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.nav_list_layout, container, false);
return view;
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
ArrayAdapter adapter = ArrayAdapter.createFromResource(getActivity(),
R.array.tab_titles, android.R.layout.simple_list_item_1);
setListAdapter(adapter);
getListView().setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
//Toast.makeText(getActivity(), "Item: " + (i +1), Toast.LENGTH_SHORT).show();
String[] tabTitlesArray = getContext().getResources().getStringArray(R.array.tab_titles);
Bundle bundle = new Bundle();
bundle.putString("tab_titles", tabTitlesArray[i].toString());
bundle.putInt("tab_int", i); //Added
// set Fragmentclass Arguments
SwipeNav fragobj = new SwipeNav();
fragobj.setArguments(bundle);
FragmentManager fm=getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(((ViewGroup)(getView().getParent())).getId(), fragobj);
ft.addToBackStack(null);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.commit();
//Fragment f=getFragmentManager().findFragmentById(R.id.fragment12);
// if(f==null){
// getFragmentManager().beginTransaction().replace(((ViewGroup)(getView().getParent())).getId(), new SwipeNav()).commit();
// }
}
});
}
// Toast.makeText(getActivity(), "Item: " + (position +1), Toast.LENGTH_SHORT).show();
// Create new fragment and transaction
}
SwipeNav.java:
public class SwipeNav extends Fragment {
private MyPagerAdapter myPagerAdapter;
private ViewPager viewPager;
private int tab_int; //Added
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
//returning our layout file
//change R.layout.yourlayoutfilename for each of your fragments
//String passingString = getArguments().getString("TAG");
if (getArguments() != null && !getArguments().isEmpty()) {
Bundle bundle = this.getArguments();
String myInt = bundle.getString("tab_titles");
tab_int = bundle.getInt("tab_int"); //Added
return inflater.inflate(R.layout.nav_swipe, container, false);
} else {
return inflater.inflate(R.layout.nav_swipe, container, false);
}
}
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
myPagerAdapter = new MyPagerAdapter(getChildFragmentManager(),getContext());
viewPager = (ViewPager) view.findViewById(R.id.pager);
//viewPager.setId( R.id.pager );
viewPager.setAdapter(myPagerAdapter);
viewPager.setCurrentItem(tab_int); //Added
//you can set the title for your toolbar here for different fragments different titles
getActivity().setTitle("Satyanusaran Bengali");
}
}
Hope that helps!
I have a MainActivity (extends Activity) and the a FooFragment (extends Fragment).
Activity uses newFooInstance method to instantiate FooFragment and set some arguments to it:
public static FooFragment newInstance(String label) {
FooFragment fooFragment = new FooFragment();
Bundle args = new Bundle();
args.putString("fooLabel", label);
fooFragment.setArguments(args);
return fooFragment;
}
Now, inside FooFragments onCreate and onCreateView I do:
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
fooLabel = getArguments().getString("fooLabel"); // null error
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(
R.layout.fragment_balanse_period, container, false
);
TextView fooView = (TextView) rootView.findViewById(R.id.fooLabel);
fooView.setText(fooLabel);
return rootView;
}
And it produces:
Attempt to invoke virtual method java.lang.String android.os.Bundle.getString(java.lang.String, java.lang.String) on a null object reference*
Any idea what am I doing wrong?
EDIT:
Defining the main activity as:
public class MainActivity extends AppCompatActivity {
Then instantiated fooFragment as:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fragments = new ArrayList<>();
fragments.add(newInstance("bar"));
// Instantiate a ViewPager and PagerAdapter
mPager = (ViewPager) findViewById(R.id.pager);
mPagerAdapter = new FooPagerAdapter(getSupportFragmentManager(), fragments);
I have found the root of evil.
Inside FooPagerAdapter the getItem was written wrong.
Wrong:
#Override
public Fragment getItem(int position) {
return new FooFragment();
}
Correct:
#Override
public Fragment getItem(int position) {
return fragments.get(position);
}
I've been trying to resolve this problem but with no result. My app is made up of 4 fragments, the second one with a recycler view. When I swipe from the first to the second my app instantly crashes. And in the logCat this error appears:
Attempt to invoke virtual method 'boolean android.support.v7.widget.RecyclerView$LayoutManager.canScrollHorizontally()' on a null object reference at android.support.v7.widget.RecyclerView.onInterceptTouchEvent(RecyclerView.java:2022)
Here's my code for the main activity:
#TargetApi(Build.VERSION_CODES.LOLLIPOP)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
toolbar = (Toolbar) findViewById(R.id.app_bar);
if (toolbar != null) {
toolbar.setTitle("Quick!");
}
setSupportActionBar(toolbar);
fragmentList.add(HomeFragment.getInstance(0));
fragmentList.add(KartFragment.getInstance(1));
fragmentList.add(FavouriteFragment.getInstance(2));
fragmentList.add(ScannerFrag.getInstance(3));
pager = (ViewPager) findViewById(R.id.Pager);
pager.setAdapter(new myPagerAdapter(getSupportFragmentManager()));
tab = (SlidingTabLayout) findViewById(R.id.SlidingTab);
tab.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
#Override
public int getIndicatorColor(int position) {
return getResources().getColor(R.color.accentColor);
}
});
tab.setViewPager(pager);
}
class myPagerAdapter extends FragmentPagerAdapter {
String[] tabs;
public myPagerAdapter(FragmentManager fm) {
super(fm);
tabs = getResources().getStringArray(R.array.tabs);
}
#Override
public Fragment getItem(int position) {
return fragmentList.get(position);
}
#Override
public CharSequence getPageTitle(int position) {
return tabs[position];
}
public int getCount() {
return fragmentList.size();
}
}
Home fragment:
public class HomeFragment extends Fragment {
private Toolbar toolbar;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View layout;
layout = inflater.inflate(R.layout.home_layout, container, false);
toolbar = (Toolbar) layout.findViewById(R.id.subToolbar);
toolbar.setTitle("Dove mangi oggi?");
return layout;
}
public static HomeFragment getInstance(int position) {
HomeFragment frag = new HomeFragment();
Bundle args = new Bundle();
args.putInt("position", position);
frag.setArguments(args);
return frag;
}
}
KartFragment:
public class KartFragment extends Fragment {
private Toolbar toolbar;
private ItemAdapter ad;
private RecyclerView rv;
private ArrayList list = new ArrayList<>();
private static final String SAVELIST = "SAVELIST";
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View layout;
if (savedInstanceState != null) {
list = savedInstanceState.getParcelableArrayList(SAVELIST);
} else {
list = KartObjectClass.listBuilder(10);
}
layout = inflater.inflate(R.layout.fragment_layout, container, false);
toolbar = (Toolbar) layout.findViewById(R.id.subToolbar);
toolbar.setTitle("I tuoi ordini:");
rv = (RecyclerView) layout.findViewById(R.id.list);
rv.setLayoutManager(new LinearLayoutManager(getActivity()));
ad = new ItemAdapter(list);
rv.setHasFixedSize(true);
rv.setAdapter(ad);
return layout;
}
#Override
public void onSaveInstanceState(Bundle outState) {
outState.putParcelableArrayList(SAVELIST, list);
super.onSaveInstanceState(outState);
}
public static KartFragment getInstance(int position) {
KartFragment frag = new KartFragment();
Bundle args = new Bundle();
args.putInt("position", position);
frag.setArguments(args);
return frag;
}
}
Favourite fragment:
public class FavouriteFragment extends Fragment {
private Toolbar toolbar;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View layout = null;
layout = inflater.inflate(R.layout.scanner_layout, container, false);
toolbar = (Toolbar) layout.findViewById(R.id.subToolbar);
toolbar.setTitle("I tuoi preferiti:");
return layout;
}
public static FavouriteFragment getInstance(int position) {
FavouriteFragment frag = new FavouriteFragment();
Bundle args = new Bundle();
args.putInt("position", position);
frag.setArguments(args);
return frag;
}
}
Try to set the LayoutManager before you set the Adapter on the RecyclerView.
I solved the error, the problem was that I had set a recycler view in the homeFragment XML. As I forgot to have it, I didn't call it in the onCreateView method and the app was crashing because no adapter was set.
Googling for three days. Can't help myself. I have navigation drawer and fragment and everything works perfect except tabs in fragment. This is part of MainActiviti Class...
case R.id.linearLayoutHome:
fragment = new HomeFragment();
break; //this one works well
case R.id.linearLayoutHome:
fragment = new CategoryFragment(); //error showing here
break; //this one doesn't work
Calling fragment...
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.container, fragment).commit();
Home fragment which works perfect:
public class HomeFragment extends Fragment {
public HomeFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_home, container, false);
return rootView;
}
}
CategoryFragment which doesn't work. I think this is because of fragment in fragment:
public class CategoriesActivity extends Fragment {
SectionsPagerAdapter mSectionsPagerAdapter;
ViewPager mViewPager;
public CategoriesActivity(){
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_home, container, false);
mSectionsPagerAdapter = new SectionsPagerAdapter(getChildFragmentManager());
mViewPager = (ViewPager) rootView.findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
return rootView;
}
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
Fragment fragment = new DummySectionFragment();
Bundle args = new Bundle();
args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1);
fragment.setArguments(args);
return fragment;
}
#Override
public int getCount() {
return 2;
}
#Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (position) {
case 0:
return getString(R.string.title1).toUpperCase(l);
case 1:
return getString(R.string.title2).toUpperCase(l);
}
return null;
}
}
public static class DummySectionFragment extends Fragment {
public static final String ARG_SECTION_NUMBER = "section_number";
public DummySectionFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_tabbed_dummy, container, false);
TextView dummyTextView = (TextView) rootView.findViewById(R.id.section_label);
dummyTextView.setText(Integer.toString(getArguments().getInt(ARG_SECTION_NUMBER)));
return rootView;
}
}
}
I need some solution. No more ideas.
STEP 1:
Your onCreateView() should look like this:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_home, container, false);
return rootView;
}
and add this method to your Fragment:
#Override
public void onViewCreated(View view, Bundle savedInstanceState){
mSectionsPagerAdapter = new SectionsPagerAdapter(getChildFragmentManager());
mViewPager = (ViewPager) view.findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
}
STEP 2:
Make sure that your Activity extends from FragmentActivity or ActionBarActivity.
STEP 3:
Make sure that you are using android.support.v4.app.Fragment and not android.app.Fragment