1

I have two fragments: fragmentA and fragmentB

In fragmentA, some views have been programmatically added

If from fragmentA I go to fragmentB and then I come back to fragmentA, all the programmatically added views are not there anymore

Which is the way to restore the programmatically added views inside the view hierarchy?

Daniele B
  • 19,801
  • 29
  • 115
  • 173
  • I think the best solution is always the logic code depend on the check value. Add it view automatically when check is false. – kemdo Mar 31 '15 at 03:13
  • what do you mean for check value? – Daniele B Mar 31 '15 at 03:14
  • 1
    Oke. Save check = true in onSaveInstanceState. Get it in onActivityCreated() when back to fragment A. and onCreate you will addView depend on you check value.... And if u want to know why "If from fragmentA I go to fragmentB and then I come back to fragmentA, all the programmatically added views are not there anymore" please post your code – kemdo Mar 31 '15 at 03:18
  • when I get back to fragment A, in onActivityCreated() the programmatically added views are never there (I am testing it using layout.getChildCount) – Daniele B Mar 31 '15 at 03:35
  • somewhere I read you need to set an id to the programmatically added view. I am specifying it using view.setId(), but they still don't get restored – Daniele B Mar 31 '15 at 03:39
  • I think onSaveInstanceState is null when you come back to FragmentA, it is different from null only when the activity is destroyed – Daniele B Mar 31 '15 at 03:42
  • sorry for long time to answer, I think u have fragment as adapter in Viewpager. – kemdo Mar 31 '15 at 04:52
  • i think the problem is very small, store check value some where(database, other class, xml,..), get it and check in oncreate. So you can do anything. Sorry if i wrong – kemdo Mar 31 '15 at 04:54

0 Answers0