我希望在长时间点击时禁用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;
}
});
}
答案 0 :(得分:2)
尝试将OnItemLongClickListener
返回值设置为true,以告知回调已被占用。如果您返回false,则认为没有消耗长按。这可能会解决您的问题