0

In my app I start with an ActionBarActivity that implements ActionBar.TabListener. In my main activity, I have a ViewPager that helps me navigate between 4 ListFragments. Each ListFragment calls a second ListFragment (ExpandableListView) that replaces it when an item is clicked.

I have noticed that inside of my second ListFragment, I am able to select one of the tabs and it updates the ViewPager/Tabs, but only in the background. The visible fragment does not move, but when it is closed, you can see that the action did take place. Is there a way that I can update the view from this second ListFragment, so that both swiping and selecting a tab will shift to one of the other 4 base fragments?

EDIT: Code that was actually requested.

     @Override
        public void onListItemClick(ListView lv, View view, int position,
                                    long id) 

{


super.onListItemClick(lv, view, position, id);

        Cursor b = ((SimpleCursorAdapter) lv.getAdapter()).getCursor();
        b.moveToPosition(position);

        String numberHelper = b.getString(b.getColumnIndex("_id"));
        int number = Integer.parseInt(numberHelper);

        Cursor c = myDB.getRow(number, fragmentIdentifier);

        String content;
        Cursor parentCursor;
        Cursor childCursor;
        Cursor conditionsCursor;
        Cursor blessingsCursor;
        Cursor favoriteCursor;
        Cursor favoriteHelperCursor;

        switch ( fragmentIdentifierHelper )
        {
            // favorite
            case 0:
                content = c.getString(c.getColumnIndex(DataBaseHelper.KEY_BOOK));
                parentCursor = myDB.getRowsFavorites(content);
                childCursor = myDB.getRowsFavorites(content);
                conditionsCursor = myDB.getRowsFavorites(content);
                blessingsCursor = myDB.getRowsFavorites(content);
                favoriteCursor = myDB.getRowsFavorites(content);
                favoriteHelperCursor = myDB.getRowsFavorites(content);
                break;

            // condition
            case 1:
                content = c.getString(c.getColumnIndex(DataBaseHelper.KEY_CONDITION));
                parentCursor = myDB.getRowsCondition(content);
                childCursor = myDB.getRowsCondition(content);
                conditionsCursor = myDB.getRowsCondition(content);
                blessingsCursor = myDB.getRowsCondition(content);
                favoriteCursor = myDB.getRowsCondition(content);
                favoriteHelperCursor = myDB.getRowsCondition(content);
                break;

            // blessing
            case 2:
                content = c.getString(c.getColumnIndex(DataBaseHelper.KEY_BLESSING));
                parentCursor = myDB.getRowsBlessing(content);
                childCursor = myDB.getRowsBlessing(content);
                conditionsCursor = myDB.getRowsBlessing(content);
                blessingsCursor = myDB.getRowsBlessing(content);
                favoriteCursor = myDB.getRowsBlessing(content);
                favoriteHelperCursor = myDB.getRowsBlessing(content);
                break;

            // chronological
            case 3:
                content = c.getString(c.getColumnIndex(DataBaseHelper.KEY_BOOK));
                parentCursor = myDB.getRowsBook(content);
                childCursor = myDB.getRowsBook(content);
                conditionsCursor = myDB.getRowsBook(content);
                blessingsCursor = myDB.getRowsBook(content);
                favoriteCursor = myDB.getRowsBook(content);
                favoriteHelperCursor = myDB.getRowsBook(content);
                break;

            default:
                content = null;
                parentCursor = null;
                childCursor = null;
                conditionsCursor = null;
                blessingsCursor = null;
                favoriteCursor = null;
                favoriteHelperCursor = null;
                break;
        }

        c = null;

        Fragment contentList = new FragmentContentList(parentListGetter(parentCursor),
                childListGetter(childCursor), conditionsListGetter(conditionsCursor),
                blessingsListGetter(blessingsCursor), favoriteGetter(favoriteCursor),
                favoriteHelper(favoriteHelperCursor));

        getFragmentManager().beginTransaction()
                .addToBackStack(null)
                .replace(android.R.id.content, contentList)
                .commit();
    }

Thanks.

Joshua Sutherland
  • 1,256
  • 4
  • 16
  • 30
  • *Is there a way that I can update the view from this second ListFragment...* - yes there is. Post some code to see what you're doing now. – user May 30 '14 at 18:04
  • @Luksprog what would be best for me to post? I've got my MainActivity, the adapter for the ViewPager used in the MainActivity, as well as both fragment levels. – Joshua Sutherland May 30 '14 at 18:19
  • You should post the code where you make the change between the two tab types of fragments to see exactly how you do it. – user May 31 '14 at 04:45
  • I was talking about the code where the initial `ListFragment` gets replaced with the `ExpandableListView` based `ListFragment`. My assumption is that you do a direct replace transaction on a container holding the ViewPager(or maybe the ViewPager itself?), this would be wrong and not the way to do what you want. Check this old answer of mine and see if it's not by any chance what you're trying to do http://stackoverflow.com/questions/13379194/how-to-add-a-fragment-inside-a-viewpager-using-nested-fragment-android-4-2/13381792#13381792 – user May 31 '14 at 14:26
  • I'll take a look at that and see if I can't figure out how to get it to work. I don't know if what I updated the code to is more of what you are looking for. But taking a quick glance at what you have up on that other page, it looks like I want a fragment that will hold my `ListView` fragment and then will also have my `ExpandableListView` fragment? – Joshua Sutherland May 31 '14 at 17:50
  • As I suspected you're replacing the ViewPager itself with a new fragment expecting the tabs and swiping to still work(which will not happen). Also, avoid using a constructor with parameters to pass data to it(unless you call setArguments()?). The idea of that answer is to have a master fragment(which will basically only consist of a container like FrameLayout), which will hold the two fragments that will be swapped between. This fragment will be used as the tab in the ViewPager and initially will contain your current start fragment. The next fragment will be swapped... – user May 31 '14 at 18:36
  • ...in place with the getChildFragmentManager()(adding to the base container). Also, changing tab content like you're trying to do is not quite a good UX action, maybe you could think of a better alternative. – user May 31 '14 at 18:36

0 Answers0