Android 警报对话框未显示,请告诉我该怎么做
我不知道我的代码出了什么问题,因为我什么都试过了。我创建了警报对话框,我看到的所有网页都显示了警报对话框。我的应用程序不显示对话框。这是Main.java:Android 警报对话框未显示,请告诉我该怎么做,android,google-maps,android-alertdialog,Android,Google Maps,Android Alertdialog,我不知道我的代码出了什么问题,因为我什么都试过了。我创建了警报对话框,我看到的所有网页都显示了警报对话框。我的应用程序不显示对话框。这是Main.java: package com.natasam.mapstwo; import java.util.List; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.content.DialogInterface; impor
package com.natasam.mapstwo;
import java.util.List;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.MotionEvent;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
public class Main extends MapActivity {
MapView map;
long start;
long stop;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
map= (MapView)findViewById(R.id.mvMain);
map.setBuiltInZoomControls(true);
Touch t= new Touch();
List<Overlay> overlayList = map.getOverlays();
overlayList.add(t);
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
class Touch extends Overlay{
public boolean OnTouchEvent(MotionEvent e, MapView v){
if(e.getAction()== MotionEvent.ACTION_DOWN){
start=e.getEventTime();
}
if(e.getAction()== MotionEvent.ACTION_UP){
stop=e.getEventTime();
}
if(stop- start > 1500){
Builder alert=new AlertDialog.Builder(Main.this);
alert.setTitle("pick an option");
alert.setMessage("You must pick an option");
alert.setPositiveButton("option 1", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
alert.setNegativeButton("pick address", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
alert.setNeutralButton("option 3", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
alert.create();
alert.show();
return true;
}
return false;
}
}
}
package com.natasam.mapstwo;
导入java.util.List;
导入android.app.AlertDialog;
导入android.app.AlertDialog.Builder;
导入android.content.DialogInterface;
导入android.os.Bundle;
导入android.view.MotionEvent;
导入com.google.android.maps.MapActivity;
导入com.google.android.maps.MapView;
导入com.google.android.maps.Overlay;
公共类主活动{
地图视图;
长起点;
长停;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
map=(MapView)findViewById(R.id.mvMain);
map.setBuiltInZoomControls(真);
触摸t=新触摸();
List overlayList=map.getOverlays();
叠加列表。添加(t);
}
@凌驾
受保护的布尔值isRouteDisplayed(){
返回false;
}
类接触扩展覆盖{
公共布尔OnTouchEvent(MotionEvent e,MapView v){
如果(e.getAction()==MotionEvent.ACTION\u DOWN){
start=e.getEventTime();
}
如果(e.getAction()==MotionEvent.ACTION\u UP){
stop=e.getEventTime();
}
如果(停止-启动>1500){
Builder alert=new AlertDialog.Builder(Main.this);
alert.setTitle(“选择选项”);
setMessage(“您必须选择一个选项”);
alert.setPositiveButton(“选项1”,新的DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int which){
//TODO自动生成的方法存根
}
});
alert.setNegativeButton(“拾取地址”,新建DialogInterface.OnClickListener()){
public void onClick(DialogInterface dialog,int which){
//TODO自动生成的方法存根
}
});
alert.setNeutralButton(“选项3”,新的DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int which){
//TODO自动生成的方法存根
}
});
alert.create();
alert.show();
返回true;
}
返回false;
}
}
}
这是.xml文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.google.android.maps.MapView
android:id="@+id/mvMain"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="a valid key" />
</RelativeLayout>
并表明:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.natasam.mapstwo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<uses-library android:name="com.google.android.maps" />
<activity
android:name=".Main"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
怎么了?它显示映射但不显示警报对话框…您正在实现的
OnTouchEvent
,而不是
请尝试以下方法:
@Override // Yes, use @Override
public boolean onTouchEvent(MotionEvent e, MapView v){
一旦更改了它,就使用
android.util.Log.i(…)代码>或系统输出打印项(…)
以确保您的触摸事件甚至被调用。就像我之前问过的一样,当您问同样的问题时,您没有回答,您是否在调试器中停止并检查start和stop的值?当我尝试添加Override iy时,可能会重复iy给我一个错误,上面说删除覆盖注释,因为Touch必须覆盖超类方法。Eric,非常感谢!:)我添加了它,比如@重写公共布尔OnTouChEvEnter(MyTevEnter E,MavVIEW映射){和OT!!!如果我的答案对你有帮助,考虑把它标记为正确的,它会帮助其他人找到它,并帮助你在将来得到更好的答案。