java - Make sub-View Listen for Double-Click in AndroidStudio -
i have following code in oncreate method of activity:
gridlayout gridlayout = new gridlayout(this); gridlayout.setcolumncount(5); gridlayout.setrowcount(5); (int = 0; < 25; i++) { imageview imageview = new imageview(this); gridlayout.addview(imageview, i); } setcontentview(gridlayout);
now, i'd each imageview in gridlayout respond (listen for) double-click. how can go doing this? (i've used long-press on 1 of views perform different action can't use instead, although realize easier since there's native listener it.)
you have 2 options:
1) use boolean handler (like this answer)
- add
boolean doubleclick = false;
- and
handler doublehandler
- in onclick check if
doubleclick true
- if true, double click
- if not, set
doubleclick
true , use handlerspostdelayed
set false after i.e. 500ms
- if not, set
2) use gesturelistener ( ondoubletap()
method )
Comments
Post a Comment