user3579107
user3579107

Reputation: 1369

Combining ListFragment and Fragment with a TabsPagerAdapter which only accepts fragments

I have a TabsPagerAdapter which only allows me to call Fragments, so I can't call a ListFragment

public class TabsPagerAdapter extends FragmentPagerAdapter {

public TabsPagerAdapter(FragmentManager fm) {
    super(fm);
}

@Override
public Fragment getItem(int index) {

    switch (index) {
        case 0:
            // Top Rated fragment activity
            return new InformacionFragment();
        case 1:
            // Games fragment activity
            return new ProductosFragment();
        case 2:
            // Movies fragment activity
            return new MoviesFragment();
    }

    return null;
}

@Override
public int getCount() {
    // get item count - equal to number of tabs
    return 3;
}}

This is ProductosFragment, where I want to set the ListFragment:

public class ProductosFragment extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
    return inflater.inflate(R.layout.zfragment_conjunta, container, false);

                                                        }
                                                }

And this is the ListFragment I want to include: http://pastebin.com/AXuXWvmd

Upvotes: 0

Views: 201

Answers (2)

user3579107
user3579107

Reputation: 1369

I finally solved it, I wasn't using Android Support v4 for importing Fragments, with this lines in import I fixed it, allowing to return a ListFragment instead a Fragment

In TabsPagerAdapter:

import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter;

In ListFragment class:

import android.support.v4.app.ListFragment;

Upvotes: 1

Eymen
Eymen

Reputation: 141

Can you paste any error logs you have? But are you trying to include ListFragment within a Fragment, if yes why? Just directly include the ListFragment as it's just a fragment with an empty list.

Try to replace :

case 1: // Games fragment activity return new ProductosFragment();

with

case 1: // Games fragment activity return new ConjuntaFragment();

Upvotes: 0

Related Questions