您好,我正在制作一个 Android 应用程序,它使用地理位置/Google map ,除了选项卡主机之外, map /应用程序上没有任何按钮。所以我需要它,所以如果用户点击 1500 毫秒,就会出现一个对话框,到目前为止没有任何反应,但我没有收到任何错误,这是我的代码,提前致谢
class Touchy extends Overlay{
public boolean ontouchevent(MotionEvent e, MapView m){
if (e.getAction() == MotionEvent.ACTION_DOWN){
start = e.getEventTime();
}
if (e.getAction() == MotionEvent.ACTION_UP){
stop = e.getEventTime();
}
if (stop - start > 1500){
AlertDialog alert = new AlertDialog.Builder(SPtouch2fixActivity.this).create();
alert.setTitle("Alert");
alert.setMessage("This is an alert");
alert.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
alert.setButton2("Update Geolocation", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
alert.setButton3("cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
alert.show();
return true;
}
return false;
}
}
}
最佳答案
我也遇到了同样的问题,经过四天的奋战终于解决了!
问题是您在方法顶部缺少@Override
。
为了解决此问题,请将代码编辑为:
@Override
public boolean ontouchevent(MotionEvent e, MapView m) {
if (e.getAction() == MotionEvent.ACTION_DOWN) {
start = e.getEventTime();
}
}
希望它对您有用。
关于java - Android Motionevent 叠加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8764260/