[英]How to access to a position of a Fragment listview item from another Fragment
I have a Fragment which contains a listview of some tones.And I have another Fragment which contains a listview of favorited items from the First Fragment. 我有一个片段,其中包含一些音调的列表视图。还有另一个片段,其中包含来自第一个片段的收藏项的列表视图。 If a user in the main Fragment wants to unmark an Item as favorite, I have to check if that specific item is playing or not. 如果主要Fragment中的用户想要取消将某个项目标记为收藏,我必须检查该特定项目是否在播放。 Hence, I need to access to an int variable named position
from my main Fragment. 因此,我需要从我的主Fragment访问一个名为position
的int变量。
a method inside Favorite Fragment: 收藏片段中的方法:
public void stopSong(int position){
int selectedSong = soundList.get(position).getRes();
}
access that method from Main Fragment : 从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
}
}
Can you help me with this, please? 您能帮我吗?
use FragmentTransaction to switch the fragment, and add a argument z.setArguments(getIntent().getExtras());
使用FragmentTransaction切换片段,并添加参数z.setArguments(getIntent().getExtras());
later,execute the method stopSong
稍后,执行方法stopSong
I advise into the service to stop the music, should not be controlled from UI[Fragment] 我建议您进入该服务以停止音乐,不应通过UI [Fragment]对其进行控制
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.