就和类似qq消息双击就就会变大一样的,我想问下怎么写双击监听textview事件,网上试了什么onclick判断时间小于多少的方法不行,重写ontouch也不行,而且我看GestureDetector的构造方法... 就和类似qq消息双击就就会变大一样的,我想问下怎么写双击监听textview事件,网上试了什么onclick判断时间小于多少的方法不行,重写ontouch也不行,而且我看GestureDetector 的构造方法也只有监听整个content,只能对上下文进行双击监听。

简单描述:就是对textview进行双击监听,最好有代码,谢谢......

这个我实现了,但是也是用记录上次点击时间的方法,代码给你看下。

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.sinovoice.test.R;

public class DoubleClickActivity extends Activity {
    private static final String TAG = "DoubleClickActivity";

    private int clickCount;
    private long preClickTime;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView tv = (TextView) findViewById(R.id.tv_main);
        clickCount = 0;
        tv.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (clickCount == 0) {
                    preClickTime = System.currentTimeMillis();
                    clickCount++;
                } else if (clickCount == 1) {
                    long curTime = System.currentTimeMillis();
                    if((curTime - preClickTime) < 500){
                        doubleClick();
                    }
                    clickCount = 0;
                    preClickTime = 0;
                }else{
                    Log.e(TAG, "clickCount = " + clickCount);
                    clickCount = 0;
                    preClickTime = 0;
                }
            }
        });
    }

    private void doubleClick() {
        Log.i(TAG, "double click");
    }
}
public abstract class OnDoubleClickLinstener implements OnclickListener{
    public abstract void onDoubleClick(View v);
    @override
    public void onClick(View v){
        if(ToolUtils.isNotDoubleClick()){
            return ;
        }
        onDoubleClick(v);
    }
}


判断类

public class ToolUtils{
    private static long lastClickTime = 0;
    public static boolean isNotDoubleClick(){
        long time = System.currentTimeMillis();
        long diff = time - lastClickTime;
        lastClickTime = time;
        if( diff>0 && diff<500 ){
            return false;
        }
        return ture;
    }
}