码:
gallery=(gallery)findVIEwByID(R.ID.gall1); gallery.setAdapter(new ImageAdapter(MainActivity.this)); gallery.setonItemClickListener(new OnItemClickListener() { @OverrIDe public voID onItemClick( AdapterVIEw<?> parent,VIEw v,int position,long ID) { // Todo auto-generated method stub final ImageVIEw imageVIEw = (ImageVIEw) findVIEwByID(R.ID.image1); imageVIEw.setimageResource(imageIDs[position]); imageVIEw.setLongClickable(true); imageVIEw.setonLongClickListener(new VIEw.OnLongClickListener(){ @OverrIDe public boolean onLongClick(VIEw v) { // Todo auto-generated method stub Toast.makeText(getApplicationContext(),"Long Press work",Toast.LENGTH_SHORT).show(); return true; } }); imageVIEw.setontouchListener(new VIEw.OntouchListener() { @OverrIDe public boolean ontouch(VIEw v,MotionEvent event) { // Todo auto-generated method stub layoutParams = (relativeLayout.LayoutParams) imageVIEw.getLayoutParams(); switch(event.getAction()) { case MotionEvent.ACTION_DOWN : { parms = (relativeLayout.LayoutParams) imageVIEw.getLayoutParams(); dx = event.getRawX() - parms.leftmargin; dy = event.getRawY() - parms.topmargin; } break; case MotionEvent.ACTION_MOVE :{ x = event.getRawX(); y = event.getRawY(); parms.leftmargin = (int) (x-dx); parms.topmargin = (int) (y - dy); imageVIEw.setLayoutParams(parms); } break; case MotionEvent.ACTION_UP : { } break; } return true; }}); } });解决方法 您需要按代码启用长按:
imageVIEw.setLongClickable(true);imageVIEw.setClickable(true);
最后一行可能没有必要,但也没有问题.
总结以上是内存溢出为你收集整理的android – OnLongClickListener不工作全部内容,希望文章能够帮你解决android – OnLongClickListener不工作所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)