2

我想在长按时禁用 onItemclicklistener。问题是我在网格视图的 onItemclick 上播放视频。我想在 onItemLongclick 上做一些其他的任务。但是当我长按时它正在播放视频并执行其他任务..这是我的代码。

gv.setOnItemClickListener(new OnItemClickListener() {
        @SuppressWarnings("deprecation")
        public void onItemClick(AdapterView<?> parent, View v,final int position, long id) {

        Log.d(TAG, "got in onItemClick of Item  "+position);
        System.gc();
         Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
         String[] cols = new String[]{
                MediaStore.Video.VideoColumns._ID,
                MediaStore.Video.VideoColumns.DISPLAY_NAME,
                MediaStore.Video.VideoColumns.DATA};
         Cursor c;
         c = managedQuery(uri, cols, null, null, MediaStore.Video.VideoColumns.DATE_TAKEN);
         c.moveToFirst();
         int mPath = c.getColumnIndexOrThrow(MediaStore.Video.VideoColumns.DATA);
         c.moveToPosition(position);
         String filename = c.getString(mPath);
         Log.d(TAG, "video position is " + position+ " video path is " + filename);
         Intent intent = new Intent(Isabella_galleryActivity.this, ViewVideo.class);
         intent.setDataAndType(uri, "video/*");
         intent.putExtra("videofilename", filename);
         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         startActivity(intent);
        }
    });


gv.setOnItemLongClickListener(new OnItemLongClickListener() {

        //@Override
        public boolean onItemLongClick(AdapterView<?> parent, View v,
                int position, long id) {
            Log.d(TAG, "got in onItemLongClick of Item  "+position);// TODO Auto-generated method stub
            //del_image = (ImageView)findViewById(R.id.video_delet_image);
            //del_image.setVisibility(View.VISIBLE);
            //gv.setClickable(false);
            div.setVisibility(View.VISIBLE);
            div.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    Log.w(TAG, "deleting the video");

                }
            });
            return false;
        }
       });
    }
4

1 回答 1

2

尝试将OnItemLongClickListener返回值设置为 true 以告知回调已被使用。如果您返回 false 它认为长点击没有被消耗。这可能会解决您的问题

于 2013-03-11T06:49:31.213 回答