在 Adapter 的 getView() 方法内部访问一个变量。

huangapple 未分类评论48阅读模式
英文:

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();
    } }

huangapple
  • 本文由 发表于 2020年4月11日 10:53:44
  • 转载请务必保留本文链接:https://java.coder-hub.com/61151539.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定