Issue with Android's onTouchEvent() -
i creating first android app using this guide reference. currently, have red button on canvas , when user clicks button boolean (green) set true in order button's bitmap green button.
that part of application works, works regardless user clicks on canvas. want boolean changed when user clicks on button's bitmap. here have in code:
the ontouchevent() method
@override public boolean ontouchevent(motionevent event) { if (event.getaction() == motionevent.action_down) { button.handleactiondown((int)event.getx(), (int)event.gety()); if (button.istouched()) { green = true; } } if (event.getaction() == motionevent.action_move) { } if (event.getaction() == motionevent.action_up) { if (button.istouched()) { green = false; button.settouched(false); } } return true; } the handleactiondown() method
public void handleactiondown(int eventx, int eventy) { if (eventx >= (x - bitmap.getwidth() / 2) && (eventx <= (x + bitmap.getwidth()/2))) { if (eventy >= (y - bitmap.getheight() / 2) && (eventy <= (y + bitmap.getheight()/2))) { settouched(true); } else { settouched(false); } } else { settouched(false); } } can see missing in order action_down event make triggers when bitmap's bitmap touched?
regards
where initialize button:
btn.setonclicklistener(this) do not use ontouchevent buttons, better use onclick
@override public void onclick(view v) { if(v.getid() == r.id.btn1){ //do whatever want on press } }
Comments
Post a Comment