android - How do I detect if a touch event has landed within an EditText? -
i can find getx(), , gety() both return float. how detect if coordinates of touchevent e.get(), e.gety() within boundaries of edittext ui element? notice getx() , gety() floats getheight(), , getwidth() int. not going comparisons ...
what want do? if want detect if edittext touched, add ontouchlistener edittext... or onclicklistener.
edit: if want detect outside, can detect touch event in containing view, , then, given have edittext view:
rect edittextrect = new rect(); myedittext.gethitrect(edittextrect); if (!edittextrect.contains((int)event.getx(), (int)event.gety())) { log.d("test", "touch not inside myedittext"); }
or add touch listener both edittext , container, , return false in 1 of edittext, way intercepted , not forwarded parent. so, touches detect in listener of parent, not belong edittext.
Comments
Post a Comment