2

I have successfully gotten a 3 tab + pager implemented.

One of these tabs is a List fragment, how would I update the fragment with the onclick method, and still be able to keep the tabs??

SquiresSquire
  • 2,404
  • 4
  • 23
  • 39

1 Answers1

1

You cannot replace a fragment defined statically in the layout file. You can only replace fragments that you added dynamically via a FragmentTransaction.as here

You can only replace a "dynamically added fragment".

private void addDynamicFragment() {
        // TODO Auto-generated method stub
               // creating instance of the HelloWorldFragment.
        Fragment fg = HelloWorldFragment.newInstance();
        // adding fragment to relative layout by using layout id
        getFragmentManager().beginTransaction().add(R.id.layout, fg).commit();
    }

So, if you want to add a dynamic fragment, see this example check this link

Community
  • 1
  • 1
kyogs
  • 6,766
  • 1
  • 34
  • 50
  • I have used code to make the tab bar and then the tab/pager changes the fragment depending on position, one of those fragments has a listview, I want to know how to add another fragment with the onclick methkd – SquiresSquire May 18 '13 at 07:55
  • see above link and above method to change fragment dynamically. – kyogs May 18 '13 at 08:19
  • I have implemented it as you have suggested but it now shows the old fragment underneath the new one, see image: http://www.philnickl.com/wosm/fragment_error.png – SquiresSquire May 20 '13 at 12:00
  • so you need to remove old one. – kyogs May 20 '13 at 12:44
  • how do I reference the old one from inside another actiity – SquiresSquire May 20 '13 at 12:54
  • http://stackoverflow.com/questions/8432228/actionbar-tabs-pager-detail-fragments-inside-viewpager-container?rq=1...hello check here. – kyogs May 20 '13 at 12:57