Communicating between a fragment and an activity - best practices

后端 未结 9 1305
予麋鹿
予麋鹿 2020-11-22 02:45

This question is mostly to solicit opinions on the best way to handle my app. I have three fragments being handled by one activity. Fragment A has one clickable element th

9条回答
  •  情歌与酒
    2020-11-22 03:32

    The suggested method for communicating between fragments is to use callbacks\listeners that are managed by your main Activity.

    I think the code on this page is pretty clear: http://developer.android.com/training/basics/fragments/communicating.html

    You can also reference the IO 2012 Schedule app, which is designed to be a de-facto reference app. It can be found here: http://code.google.com/p/iosched/

    Also, here is a SO question with good info: How to pass data between fragments

提交回复
热议问题