1

I cannot for the life of me figure out how to update a Fragment/entire FragmentManager. I'm using the FragmentManager that comes with the SDK (sliding tabs) and inside one is a form for a login. When the login is finished (which I have figured out, it uses an AsyncTask) I'd like to reupdate the entire FragmentManager section. FragmentTransactions have failed me (or at least I couldn't get them to work) so I'm wondering what's the best way to just refresh the UI.

Also, I have the custom menu with a logout button. When the user logs out, it should also refresh the UI (the tabs change based on whether or not the user is logged in).

TL;DR How do I refresh/reload an entire fragment system from inside and outside of the Fragments?

Also another thing that would be helpful, how do I make a Fragment update with new information (passing an array or a JSON array) after a different AsyncTask completes?

Zane
  • 4,652
  • 1
  • 29
  • 26

1 Answers1

0

You would have to paste some of your code to see what is wrong with the FragmentManager. Transactions should be completed after you call <FragmentManager>.commit().

In regards to your second question:

To get your Fragment to update with new information, you should be able to just add a method like normal to your Fragment and call it. If you are calling the method from the AsyncTask then just be careful with Context. Take a look at this:

How to call parent activity function from ASyncTask?

Community
  • 1
  • 1
telkins
  • 10,440
  • 8
  • 52
  • 79
  • I think I figured out what was going on with the Fragment not updating on commit(), I believe it was updating just not passing the information correctly (hence no *actual* visible update to the UI). On the other hand, I still have no idea how to update the UI from part of Fragment because as far as I can tell, Fragment's `public View onCreateView(LayoutInflater linf, ViewGroup cont, Bundle savedInstanceState) {` creates many problems, because it *returns* the `View`. How would I tell the UI to call this again to get the new `View`? – Zane Jul 25 '12 at 22:23
  • It depends what exactly you are doing. Generally you can just update the data source and not have to completely recreate the `View`. For instance, in one of my `Fragments` I have a `ListView` and when I pass data to it from my `Activity` I internally call `notifyDataSetChanged()` and the adapter updates for me. You can also use `getView()` to get a reference to the `View` that the `Fragment` is using and then access any methods such as `setText()`. – telkins Jul 25 '12 at 23:29