androidEnthusiast
androidEnthusiast

Reputation: 1160

Alert Dialog is not showing, please tell me what to do

I don't know what is wrong in my code because I tried everything. I created Alert Dialog and all of the web I've seen that Alert dialog appears for everybody else. My app doesn't show dialog. This is Main.java:

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;

        }
    }
}

And this is .xml file:

<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>

And Manifest:

<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>

What is wrong? It shows map but not alert dialog...

Upvotes: 0

Views: 391

Answers (1)

Cat
Cat

Reputation: 67512

You are implementing OnTouchEvent, not onTouchEvent.

Try this instead:

@Override // Yes, use @Override
public boolean onTouchEvent(MotionEvent e, MapView v){

Once you've changed it, use android.util.Log.i(...); or System.out.println(...); to ensure your touch event is even getting called.

Upvotes: 1

Related Questions