我是Android的新手,但我已经设法按照一些教程开始让我开始..我想做的是,一旦用户在屏幕上触摸了更多,就会出现一个带有三个按钮的警报对话框比2(秒)我遇到的问题是当我启动它时ALERTDIALOG Box没有出现在地图上..我没有得到任何错误?有人可以帮助我。
以下是我的代码......
long start;
long stop;
//reference map from citymap.xml file
map = (MapView) findViewById(R.id.mvMain);
// Enable zoom features
map.setBuiltInZoomControls(false);
//Declaring the instance Interaction
Interact t = new Interact();
//declaring a list of overlays
List<Overlay> overlayList = map.getOverlays();
// interact t in to overlay list.
overlayList.add(t);
class Interact extends Overlay {
public boolean OnTouchEvent(MotionEvent e, MapView m){
// initiating motion event action down
if(e.getAction() == MotionEvent.ACTION_DOWN){
// set start time
start = e.getEventTime();
}
// Initiating motion event action up: when the user stops on touch event
if(e.getAction() == MotionEvent.ACTION_UP){
// set end time
stop = e.getEventTime();
}
// calculating the time to project an alert dialog
if (stop > 1500){
Toast.makeText(CityMap.this, "toast meee", 50000).show();
//perform an action, create alert dialog box
AlertDialog.Builder builder = new AlertDialog.Builder(CityMap.this).create();
builder.setTitle("Select an Option");
builder.setCancelable(true);
builder.setPositiveButton("Place pint Point", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
builder.create();
builder.show();
return true;
}
return true;
答案 0 :(得分:0)
我认为你搞砸了最后一句if语句。尝试第二次返回false。
查看我的:
if (stop - start > 1500) {
// perform some action
AlertDialog alert = new AlertDialog.Builder(Main.this).create();
alert.setTitle("Pick an option");
alert.setMessage("Pick an option dude!");
alert.setButton("Place a pin",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
// TODO Auto-generated method stub
}
});
希望这会有所帮助;)
答案 1 :(得分:0)
对于@Pepys:不推荐使用此方法。你应该使用
alert.setPositiveButton("your text", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {...
}});