禁用onItemclicklistener

禁用onItemclicklistener

长按时,我想禁用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;
        }
       });
    }

最佳答案

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

09-25 23:21