-2

I have survey about this subject in a day. What I mean is how to show toast when tapping the Videoview for a while.

Below is what I've found,

Android: Why can't I give an onClickListener to a VideoView?

detect double tap (Double click) or long click in a videoview

But these really can't solve my problem.I really don't know what has happend? And is there any function can fire up long pressing event in the video view?

here's my code

these two event really can't work.

    mVideoView.setOnLongClickListener(new OnLongClickListener() {

        public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
                final int arg2, long arg3) {
            Log.e("devon","onitemlongclick");
            return true;
        }

        @Override
        public boolean onLongClick(View v) {
            Log.e("devon","onLongClick");
            return true;
        }

    });

need help !!!thanks!

4

2 回答 2

3
  • setupViewComponent在您的通话中添加 OnLongClickListener
  • 尝试使用 onTouch
  • 尝试将 OnLongClickListener 附加到视频视图的表面
  • 尝试用透明的图像视图/抓住焦点的东西包裹视频视图,并将其用作您的“触摸板”
  • 发布日志猫。
于 2013-07-24T10:22:56.187 回答
0

这是一个关于如何创建自己的 TouchListsner 来管理 VideoView 上的 Click 和 LongClick 的示例示例。在此示例中,我将单击的数据的 idex 和视图的索引传递给侦听器(在后面我有几个 VideoView 数组映射到数据列表,就像在适配器中一样)

/**
 * Simple OnTouchListenerIndexed with Indexes for VideoView ClickListeners 
 * You have to handle longClick and click by yourself 
 */
private abstract class OnTouchListenerIndexed implements OnTouchListener {
    private static final int LONG_CLICK_DURATION=600;//in millis
    int dataIndex = INDEX_NOT_DEFINED;
    int imageViewIndex = INDEX_NOT_DEFINED;
    long timeActionDown;
    AtomicBoolean stillNotConsumed=new AtomicBoolean(true);
    AtomicBoolean actionDone=new AtomicBoolean(false);

    public OnTouchListenerIndexed(int dataIndex, int imageViewIndex) {
        this.dataIndex = dataIndex;
        this.imageViewIndex = imageViewIndex;
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if(event.getAction() == MotionEvent.ACTION_DOWN){
            timeActionDown=System.currentTimeMillis();
            stillNotConsumed.set(true);
            actionDone.set(false);
            //launch LongClick in 1s
            v.postDelayed(new Runnable() {
                @Override
                public void run() {
                    if(stillNotConsumed.get()){
                        stillNotConsumed.set(false);
                        actionDone.set(true);
                        onLongTouch(dataIndex, imageViewIndex);
                    }
                }
            },LONG_CLICK_DURATION);
            //consumed
            return true;
        }else if(event.getAction() == MotionEvent.ACTION_UP){
            long timeActionUp=System.currentTimeMillis();
            stillNotConsumed.set(false);
            if(actionDone.get()){
                //do nothing
                return true;//you have consumed it
            }else {
                actionDone.set(true);
                //Check Click or LongClick
                if (timeActionUp - timeActionDown > LONG_CLICK_DURATION) {
                    //une seconde plus tard
                    return onLongTouch(dataIndex, imageViewIndex);
                } else {
                    return onTouch(dataIndex, imageViewIndex);
                }
            }

        }else{
            //don't consume it
            return false;
        }
    }


    public abstract boolean onTouch(int dataIndex, int imageViewIndex);
    public abstract boolean onLongTouch(int dataIndex, int imageViewIndex);
}
于 2020-01-21T09:19:36.620 回答