android - How to detect when any child view recieves a click -


given arbitrary viewgroup g arbitrary collection of child views, how can detect when user clicks on of child views? in case, want draw highlight g.

i add onclick listener each child, i'm trying avoid code doesn't have changed when layouts change.

alternatively, add ontouch handlers g , set highlight during action_down. however, trigger actions don't result in clicks, such swipe (the swipe handled viewpager, example, , irrelevant g).

my layout g has focusable attributes:

android:focusable="true" android:focusableintouchmode="true" 

thanks.

you use view.getchildcount() loop through child views , see if touch intersects child view. involves getting x , y positions , calculating if fits within child view, use view.getchildat(position) reference child view .

so this:

int childnr = theview.getchildcount(); (int = 0; < childnr; i++){      yourview tmp = (yourview) theview.getchildat(i);      if(tmp.intersects(x, y)){           work      } } 

here have put view variable instead of theview , class name handles views instead of (yourview) , x, y coordinates of pressed spot.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -