java - How to get position of item selecte in gridview, or detect release of key with onItemClick? -
i must able detect press , release of button, must have position of item in gridview being touched. have gridview d-pad control. when user pushed on need send "go" , when release need send "stop"
with below , there no way tell when lift off button (that know!).
grid.setadapter(new imageadapter(c, mthumbids)); grid.setonitemclicklistener(new onitemclicklistener() { public void onitemclick(adapterview<?> parent, view v, int position, long id) { message msg = new message(); msg.what = what; msg.arg1 = position; chandler.sendmessage(msg); } });
but if use ontouch listner cant tell item in grid have selected
grid.setontouchlistener(new ontouchlistener() { public boolean ontouch(view v, motionevent event) { if (event.getaction() == motionevent.action_up) { message msg = new message(); msg.what = 255; msg.arg1 = 255; chandler.sendmessage(msg); } if (event.getaction() == motionevent.action_down) { message msg = new message(); msg.what = what; msg.arg1 = 55; chandler.sendmessage(msg); } return false; } });
your time appreciated !!
/// i've been trying do, can never bounds of different parts of gridview. r.getx etc returns 0. if have id of resource how can pull rectangle ?
grid.setontouchlistener(new ontouchlistener() { public boolean ontouch(view v, motionevent event) { if (event.getaction() == motionevent.action_up) { rect r = new rect(); imageview imageview = new imageview(c); for(int n: mthumbids){ imageview.setimageresource(n); r = imageview.getdrawable().getbounds(); if(r.contains((int)event.getx(),(int)event.gety())) { message msg = new message(); msg.what = what; msg.arg1 = n; msg.arg2 = (int)event.getrawy(); chandler.sendmessage(msg); break; }else{ message msg = new message(); msg.what = what; msg.arg1 = r.centerx(); msg.arg2 = n; chandler.sendmessage(msg); } }// end }// end if action
michael , have 2 choices such implementation
- set onclicklistener on each of widgets in each grid item(eg.textview/imageview)
or
and you're done!
Comments
Post a Comment