sgattani / TwitterApp

A slightly more mature twitter client for Android
0 stars 0 forks source link

[Android BootCamp] Need help with communicating from activity to fragment #1

Closed sgattani closed 11 years ago

sgattani commented 11 years ago

@nesquena @timothy1ee

Hey Guys:

I have made an initial commit which covers a fair bit of the use cases. Still need to add per user profiles and fix offline storage and some data integrity issues.

I have the following question. How would I go about communicating a refresh from the activity to the fragment. For example, if the user pushes compose (this is on the activity menu bar) and sends out a tweet, I would like to go back to the activity and only if the user is on HomeTimeLine tab, I would like to tell the HomeTimeLineFragment to refresh itself. How do I achieve this cleanly.

Similarly, if I wanted to have a refresh button on the menu bar (I am doing pull to refresh, but in case I wanted the button as well), how would I tell which fragment needs to refresh. I was adding the refresh button from the activity and not the fragment.

Just realized that if fragments load all of their own menu bar options each time they load then this problem would be easily solved. I will investigate that!.

nesquena commented 11 years ago

I have the following question. How would I go about communicating a refresh from the activity to the fragment. For example, if the user pushes compose (this is on the activity menu bar) and sends out a tweet, I would like to go back to the activity and only if the user is on HomeTimeLine tab, I would like to tell the HomeTimeLineFragment to refresh itself. How do I achieve this cleanly.

You could add a public method to the fragment (i.e refreshTimeline) and then in onActivityResult like normal after coming back from compose you could check to see the selected tab from the ActionBar (or just the index and only take the action if the expected tab is selected.

Just realized that if fragments load all of their own menu bar options each time they load then this problem would be easily solved. I will investigate that!.

Yep, it's simple when you add the action items from within the fragment itself: http://www.grokkingandroid.com/adding-action-items-from-within-fragments/

Let me know if I missed a question. I will review this homework once you've finished it off.

nesquena commented 11 years ago

@sgattani In case you have any more issues, we can remote pair with screenhero or I can answer them here just let me know.

sgattani commented 11 years ago

All good. I implemented the first strategy suggested by you. Thanks.