英文:
Access a variable inside getView() method in an Adapter
问题
我有一个自定义的数组适配器,并且在其getView()方法中有一个媒体播放器,我想创建另一个方法,其他活动可以调用该方法,并且我希望该方法可以停止那个媒体播放器,但我既不能将其设置为getView()方法内部的公共方法,也不能将其移到外部,因为我必须从getView()方法中获取音轨ID。那么有没有一种方法可以在不将其移出getView()的情况下,从getView()之外访问它呢?
另一个问题是,我甚至不能从其他活动访问该方法,我不知道为什么?
public void stopMediaPlayer(boolean hasStopped) {
if (hasStopped) {
mediaPlayer.stop();
mediaPlayer.release();
}
}
英文:
I have a custom array adapter and I have a media player inside its getView() method and I want to make another method which other activities would be able to call and I want that method to stop that media player but I can neither make it public inside the getVeiw() nor get it out of there as I have to get the track ID from getView() method so is there a way I can access it from outside of getView without getting it out of there?
Another problem is that I can't even access that methed from other activites and I don't know why?
public void stopMediaPlayer(boolean hasStopped){
if(hasStopped){
mediaPlayer.stop();
mediaPlayer.release();
} }
专注分享java语言的经验与见解,让所有开发者获益!
评论