【发布时间】:2017-04-25 07:49:36
【问题描述】:
我有一个片段,其中包含一些音调的列表视图。我还有另一个片段,其中包含第一个片段中最喜欢的项目的列表视图。
如果主片段中的用户想要取消将某个项目标记为收藏,我必须检查该特定项目是否正在播放。因此,我需要从我的主 Fragment 访问一个名为 position 的 int 变量。
Favorite Fragment 中的一个方法:
public void stopSong(int position){
int selectedSong = soundList.get(position).getRes();
}
从 Main Fragment 访问该方法:
if (MainFragment.isPlaying==true){
MainFragment z = (MainFragment) MainFragment.mainFragment;
z.getFragmentManager().findFragmentByTag(MainFragment.ARG_ITEM_ID);
if (z!=null){
z.stopSong(position);//position that I need to get from Favorite Fragment method
}
}
你能帮我解决这个问题吗?
【问题讨论】:
-
您可以为此使用共享偏好或使用捆绑发送位置
标签: android listview android-fragments fragment