我怀疑是在特定按钮或图像视图或视图上实现的点击监听器?因为我浏览的网站只显示整个布局,我希望我的动作可以在点击视图时执行.请帮忙.谢谢.
解决方法:
可以使用onClickListener()设置任何视图,该视图类是视图类的一部分.最简单的方法是在onCreate()方法中设置对视图的引用.以下是图像视图的示例:
ImageVIEw iv = (ImageVIEw) findVIEwByID(R.ID.example);iv.setonClickListener(new VIEw.OnClickListener() { public voID onClick(VIEw v) { // Do what you need to do on click .... }});
更新:DOUBLE TAP
以下是在图像视图上实现基本双击检测的示例活动:
import androID.app.Activity;import androID.os.Bundle;import androID.os.SystemClock;import androID.vIEw.MotionEvent;import androID.vIEw.VIEw;import androID.Widget.ImageVIEw;import androID.Widget.Toast;public class DoubleTapActivity extends Activity { //Set the double tap delay in milliseconds protected static final long DOUBLE_CliCK_MAX_DELAY = 1000L; private ImageVIEw iVIEw; private long thisTime = 0; private long prevTime = 0; private boolean firstTap = true; /** Called when the activity is first created. */ @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.main); iVIEw = (ImageVIEw)findVIEwByID(R.ID.iVIEw); iVIEw.setontouchListener( new VIEw.OntouchListener() { @OverrIDe public boolean ontouch(VIEw v, MotionEvent event) { // Todo auto-generated method stub if(firstTap){ thisTime = SystemClock.uptimeMillis(); firstTap = false; } else { prevTime = thisTime; thisTime = SystemClock.uptimeMillis(); //Check that thisTime is greater than prevTime //just incase system clock reset to zero if(thisTime > prevTime){ //Check if times are within our max delay if((thisTime - prevTime) <= DOUBLE_CliCK_MAX_DELAY){ //We have detected a double tap! Toast.makeText(DoubleTapActivity.this, "DOUBLE TAP DETECTED!!!", Toast.LENGTH_LONG).show(); //PUT YOUR LOGIC HERE!!!! } else { //Otherwise reset firstTap firstTap = true; } } else { firstTap = true; } } return false; } }); }}
总结 以上是内存溢出为你收集整理的android – OnTap监听器实现全部内容,希望文章能够帮你解决android – OnTap监听器实现所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)