0

SCOPE

I am using the [PagerSlidingTabStrip][1] and I have two tabs (A and B) and a ListFragment in each tab containing 6 list items (1-6) which, when clicked, will transition to another Fragment (C).

Sample of Scope Sample of Detail View

PROBLEM

After 4 days of searching StackOverflow/Google and trying various methods I consistently end up with one or two results (excluding various errors).

1.) Using a TextView in a Fragment, the TextView String would populate between the ActionBar (Test) and Tab A.

2.) I would click on a list item and it would replace the ListFragment with a blank white Fragment (say for C).

SOURCE

MainActivity

public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Initialize the ViewPager and set an adapter
    ViewPager pager = (ViewPager) findViewById(R.id.pager);
    pager.setAdapter(new MainPagerAdapter(getSupportFragmentManager()));

    // Bind the tabs to the ViewPager
    PagerSlidingTabStrip tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
    tabs.setShouldExpand(true); // expand tabs to fill parent
    tabs.setViewPager(pager);

}

public class MainPagerAdapter extends FragmentPagerAdapter {

    private final String[] TITLES = {"A", "B"};

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

    @Override
    public CharSequence getPageTitle(int position) {
        return TITLES[position];
    }

    @Override
    public int getCount() {
        return TITLES.length;
    }

    @Override
    public Fragment getItem(int position) {

        switch (position) {
            case 0:
                return new A();
            case 1:
                return new B();
        }
        return null;
    }
}

Class A/B

public class A extends ListFragment {

    ListView list;

    final String[] items = {"1", "2", "3", "4", "5", "6"};

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.layout_a, container, false);
        list = (ListView) rootView.findViewById(android.R.id.list);
        ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, items);
        list.setAdapter(adapter);

        return rootView;
    }

    @Override
public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    // this is where I get stuck...using switch/case has resulted in the 2 results above
    }
}

Any help would be GREATLY appreciated as I've been stuck on this for almost a week and it is maddening!

ljamison
  • 115
  • 1
  • 10
  • For some reason the PagerSlidingTabStrip link didn't work so here it is. https://github.com/astuetz/PagerSlidingTabStrip – ljamison Feb 18 '15 at 15:54
  • Have you found any solution ? i face exactly the same problem.. – Manos Feb 23 '15 at 21:50
  • Unfortunately no. If I find something I'll be sure to post it for you. I think I have an idea for it which I will try tonight. – ljamison Feb 23 '15 at 21:53
  • I will try using google's method isntead the third party library. I will let you know too. http://developer.android.com/training/implementing-navigation/lateral.html – Manos Feb 23 '15 at 21:54
  • Here i think is our problem: http://stackoverflow.com/a/18940937/2200675 Fragments that are hard coded in XML, cannot be replaced – Manos Feb 23 '15 at 21:57
  • Ah..so pretty much we're dead in the water? As far as I can see anyway. – ljamison Feb 23 '15 at 22:00
  • Why would you hardcode fragments in XML for such a use case? And why would you want to embed fragment C inside the viewpager? The normal use case would be to open another activity with C as its main content. – arne.jans Sep 02 '15 at 15:41

0 Answers0