简体   繁体   中英

Android: How to update spinner data on another fragment

So I have 2 fragments Fragment1 and Fragment2. On an event in fragment 2 I would like to call the refreshSpinnerData method in Fragment1 to update the spinner in Fragment1. I'm a novice, but being that Fragment1 is an object I'd think that I could just put the following line in Fragment2. Fragment1.refreshSpinnerData();....but evidently that would just be too easy. So how do I go about doing this? Thanks for the help.

Try taking a look at Communicating with Other Fragments . In your case you would define the interface & callback in Fragment2, have your activity implement the interface, then find Fragment1 in your activity and call .refreshSpinnerData() on it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM