我想在listview上实现单击和双击

时间:2014-05-15 09:31:03

标签: android

1。)单击白色层是可见的&在行上看不见。
2.)在我的应用程序中运行双击动画。
双击动画在我的应用程序中正常运行。单点击图层是可见的,并且在下次单击时不可见但我的问题是,当我进行单击而不是图层显示但是如果我双击点击行而不是我的列表视图是不可点击的,即使我不能单击之后这一点。

int i = 0;

adapter = new MyAdapter(this, datas);
    lv.setAdapter(adapter);

    // load the animation
    animRotate = AnimationUtils.loadAnimation(getApplicationContext(),
            R.anim.rotate);
    animFadeOut = AnimationUtils.loadAnimation(getApplicationContext(),
            R.anim.fade_out);
    // set animation listener
    animRotate.setAnimationListener(this);
    animFadeOut.setAnimationListener(this);
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {

    if (!isAnimationRunning) {
        roundLogo = (ImageView) v.getTag(R.id.picture_ImageView_logoround);
        animLogo = (ImageView) v.getTag(R.id.picture_ImageView_logo);
        i++;
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                if (i == 1) {
                    i = 0;
                    if (adapter.isVisible()) {
                        // layer invisible
                    } else {
                        // layer visible

                    }
                }
            }
        };

        if (i == 1) {
            handler.postDelayed(runnable, 200);
        } else if (i == 2 && !adapter.isVisible) {
            handler.removeCallbacks(runnable);
            i = 0;
        // ANIMATION CODE HERE IT WORKS FINE

        }
    }
}

1 个答案:

答案 0 :(得分:1)

我确信,但我认为可以采用以下代码段的修改版本。

protected void onListItemClick(ListView l, View v, int position, long id) 
    {
    long timeNow=Calendar.getInstance().getTimeInMilis();
    long timeLastTapped=Long.valueOf(view.getTag); // Initially set to zero in adapter
    final int minDurationBetweenDoubleTap=500;
    if(timeLastTapped != 0)
    if( timeNow- timeLastTapped < minDurationBetweenDoubleTap) // 
    {
    //Double Tapped===> Do your stuff here
    }
    view.setTag(""+timeNow);    
    };