android - imageView clickable and scrollable -
i want able click , scroll image view happened whenever touch image view , perform "action move" not scroll perform "click event" instead! want able both meaning when touch , move should scroll when touch should perform click! in advance
this have done
imageview ivuser = (imageview) findviewbyid(r.id.ivuser); ivuser.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub intent intent = new intent(storydetails.this, profileview.class); intent.putextra("id", usersid); log.d("ivuser attempt", usersid); startactivity(intent); } });
i implemented "ontouch listener" code below don't have idea next!
ivpost.setontouchlistener(new ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { switch (event.getaction()) { case motionevent.action_down: { log.d("action_down", "action_down"); break; } case motionevent.action_move:{ log.d("action_move", "action_move"); break; } case motionevent.action_cancel:{ log.d("length_long!", "length_long"); break; } } return true; } });
image.setonclicklistener(new onclicklistener() { @override public void onclick(view arg0) { // todo auto-generated method stub toast.maketext(getbasecontext(), "image clicked", toast.length_long).show(); } }); image.setontouchlistener(new ontouchlistener() { @override public boolean ontouch(view arg0, motionevent arg1) { // todo auto-generated method stub switch (arg1.getaction()) { case motionevent.action_up: // user releases finger if(!moved){ toast.maketext(getbasecontext(), string.valueof(moved), toast.length_short).show(); image.performclick(); // use if badly need onclick listener // can replace , put onclick listener codes directly here } break; case motionevent.action_move: moved = true; toast.maketext(getbasecontext(), "image moving", toast.length_short).show(); toast.maketext(getbasecontext(), string.valueof(moved), toast.length_short).show(); // scroll stuff here, meaning put scrolling codes here break; case motionevent.action_down: //this touch trigered, can call performclick function here // b called first can boolean magic here.. moved = false; break; } return true; } });
your boolean should global variable private boolean moved; // boolean
Comments
Post a Comment