-2

I have a swipe tab view with two tabs and the two tabs are search list and My list. I have a list view in the first tab and if the user clicks on an item , that item is sent to the next tab. That is where I have my problem getting the data from one fragment to another . how can I do this please ? I have tried using a number of video tutorials but none have been able to help me make it work

3 Answers3

1

You can use a Handler. Don't forget to refresh the fragment.

stefana
  • 2,606
  • 3
  • 29
  • 47
0

You can use callback interfaces. Define an interface and implement it in your fragments. They will act like an event handler. You can find many samples on SO like this one; How to Define Callbacks in Android?

Community
  • 1
  • 1
Canberk
  • 435
  • 3
  • 10
0

Your fragments shouldn't talk to each other, or be aware of each other. The containing activity should handle the communication. See this google developer tutorial for details:

https://developer.android.com/training/basics/fragments/communicating.html

Your containing activity needs to implement a callback interface, which the fragment attaches to in an onAttach override. This callback will then pass messages to the other fragment on some event occuring in the first fragment.

Not sure why this was downvoted!

Nibor
  • 1,096
  • 8
  • 11