开发者社区> 问答> 正文

设置为null后,如何将onItemClickListener重置为true?

我在列表视图中设置了onItemClickListener,其中包括视频,图像和文本。当用户在列表视图中点击视频时,它可以正常播放。现在,在playVideo()方法内部,将listview设置为null,以便用户在播放时不应与视频进行交互。

我想重获/ RESE丁字裤的onitemClicklisterner到真正的视频结束播放后。我该如何实施,请协助。

private void playVideo() {

    listOfMessages.setOnItemClickListener(null);

    videoText.setVideoURI(Uri.parse(chattVideo));
    frameText.setVisibility(View.VISIBLE);
    imageVideo.setVisibility(View.INVISIBLE);
    videoText.setVisibility(View.VISIBLE);
    btnText.setVisibility(View.GONE);

   try {
        videoText.setMediaController(mediaControllerText);
        mediaControllerText.show();
       videoText.seekTo(1);
      videoText.pause();
       videoText.stopPlayback();
       videoText.seekTo(1);
       videoText.resume();
    progressBarMessage.setVisibility(View.GONE);
        videoText.start();

        videoText.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {

                mp.start();

                mp.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() {
                    @Override
                    public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {

                        progressBarMessage.setVisibility(View.GONE);
                        mp.start();
                    }
                });

            }
        });

        videoText.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {


               listOfMessages.setOnItemClickListener(this);// if I do like this android studio complains it cannot be applied inside MediaPlayer.OnCompletionListener
                btnText.setVisibility(View.VISIBLE);

            }
        });

        videoText.setOnErrorListener(new MediaPlayer.OnErrorListener() {
            @Override
            public boolean onError(MediaPlayer mp, int what, int extra) {

                FancyToast.makeText(getContext(),"Something went wrong!",FancyToast.LENGTH_LONG,
                        FancyToast.ERROR,R.drawable.wheel,false).show();

                return false;
            }
        });


   } catch (Exception e) {
       PBar.setVisibility(View.GONE);
        FancyToast.makeText(getContext(),e.getMessage(),
                FancyToast.LENGTH_LONG,FancyToast.WARNING,R.drawable.wheel,false).show();
    }

}

问题来源:Stack Overflow

展开
收起
montos 2020-03-23 09:42:27 738 0
1 条回答
写回答
取消 提交回答
  • 您可以按照以下方法创建所需内容

    这是伪代码

    private void setListener(boolean isPlaying){
            if(isPlaying){
                your_listview.setOnItemClickListener(null);
            }
            else{
                your_listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        //YOUR CODE
                    }
                });
            }
        }
    

    现在,只需setListener(true)在视频播放时 调用setListener(false)

    回答来源:Stack Overflow

    2020-03-25 23:14:06
    赞同 展开评论 打赏
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
How Simplicity Will Unlock the True Potential of 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载