IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

un Activity qui appele un MapActivity


Sujet :

Android

Mode arborescent

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Inscrit en
    Avril 2009
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Avril 2009
    Messages : 26
    Par défaut un Activity qui appele un MapActivity
    Bonjour à tous,

    Je fait une application de geolocalisation sous Android qui est formée par des views:
    1) le premier est un Activity qui fait apparaitre un menu
    2)Le second est un MapAvticity qui doit être lancé lorsque un item du menu est cliqué

    J'utilise StartActivityForResult mais lorsque je clique un item du menu l'application se plante comme dans l'image jointe.
    Le code est le suivant:

    i) geolocalisation.java:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    package com.android.geo;
     
    import android.app.Activity;
    import android.app.Activity.*;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.widget.Toast;
     
    public class Geolocalisation extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
        }
        private void CreateMenu(Menu menu)
        {
           // menu.setQwertyMode(true);
            MenuItem mnu1 = menu.add(0, 0, 0, "Hopitaux");
            {
                mnu1.setAlphabeticShortcut('a');
                mnu1.setIcon(R.drawable.hopital);
            //    Intent startMap = new Intent(this,Display_Map.class);
            //    mnu1.setIntent(startMap);
            }
            MenuItem mnu2 = menu.add(0, 1, 1, "Espaces Verts");
            {
                mnu2.setAlphabeticShortcut('b');
                mnu2.setIcon(R.drawable.espace_vert);            
            }
            MenuItem mnu3 = menu.add(0, 2, 2, "Item3");
            {
                mnu3.setAlphabeticShortcut('c');
                mnu3.setIcon(R.drawable.icon);
            }
            MenuItem mnu4 = menu.add(0, 3, 3, "Item 4");
            {
                mnu4.setAlphabeticShortcut('d');                    
            }
     
        }
        private boolean MenuChoice(MenuItem item)
        {        
     
            switch (item.getItemId()) {
            case 0:
            	Intent intent = new Intent(this,Map.class);
         		startActivityForResult(intent, 1234); 
                return true;
            case 1:
                Toast.makeText(this, "You clicked on Item 2", 
                    Toast.LENGTH_LONG).show(); 
                return true;
            case 2:
                Toast.makeText(this, "You clicked on Item 3", 
                    Toast.LENGTH_LONG).show(); 
                return true;
            case 3:
                Toast.makeText(this, "You clicked on Item 4", 
                    Toast.LENGTH_LONG).show();
                return true;
     
            }
            return false;
        }
        //---only created once---
     
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {// called when the MENU button is pressed
            super.onCreateOptionsMenu(menu);
            CreateMenu(menu);
            return true;
        }
     
        @Override
        public boolean onOptionsItemSelected(MenuItem item){// called when an item is selected
     
             return MenuChoice(item);    
        }
     
     
     
    }
    ii) Map.java:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    package com.android.geo;
     
     
    import android.os.Bundle;
    import android.view.KeyEvent;
     
    import com.google.android.maps.GeoPoint;
    import com.google.android.maps.MapActivity;
    import com.google.android.maps.MapController;
    import com.google.android.maps.MapView;
     
    public class Map extends MapActivity{
        private MapView myMapView;
     
        public void onCreate(Bundle icicle) {
            super.onCreate(icicle);
          //  myMapView = new MapView(this);
            myMapView = (MapView) findViewById(R.layout.map);
            // Lets start at the Statue of Liberty
            // I grabbed the data from Google-Maps
            GeoPoint p = new GeoPoint((int) (40.689213 * 1000000),
                                  (int) (-74.044558 * 1000000));
            // Get the controller, that is used for translation and zooming
            MapController mc = myMapView.getController();
            // Translate to the Statue of Liberty
            mc.animateTo(p);
            // Zoom Very close
         //   mc.zoomTo(21);
            mc.zoomOut();
            // Make myMapView the exilicit view of this app
            setContentView(myMapView);
            // Enable Sattelite-Mode, so we will se the
            // Statue of liberty instantly on the screen
            myMapView.isSatellite();
        }
     
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_I) {
                // Zooming In
             //   myMapView.getController().zoumTo(myMapView.getZoomLevel() + 1);
            	myMapView.getController().zoomIn();
                return true;
            } else if (keyCode == KeyEvent.KEYCODE_O) {
                // Zooming Out
             //   myMapView.getController().zoomTo(myMapView.getZoomLevel() - 1);
            	myMapView.getController().zoomOut();
                return true;
            } else if (keyCode == KeyEvent.KEYCODE_S) {
              // Switch to satellite view
                myMapView.isSatellite();
                return true;
            } else if (keyCode == KeyEvent.KEYCODE_T) {
                // Switch on traffic overlays
                myMapView.isTraffic();
                return true;
            }
            return false;
        }
     
    	@Override
    	protected boolean isRouteDisplayed() {
    		// TODO Auto-generated method stub
    		return false;
    	}
    }
    iii) main.xml:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >    
    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="Ecrire votre adreesse ici :"
        />
    <EditText 
    	android:text="@+id/EditText01" 
    	android:id="@+id/EditText01" 
    	android:layout_marginBottom="5px"
    	android:layout_width="wrap_content" 
    	android:layout_height="wrap_content"
    	android:background="@android:drawable/editbox_background"
    	android:singleLine="true"
    />
    </LinearLayout>
    iv) map.xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        > 
     
        <com.google.android.maps.Mapview  
        android:id="@+id/mapview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true"
        android:apiKey="0l2QH2tXpHvz10Xd87ngk4K9IokKqAf06GaJkxg"
        />
    </LinearLayout>
    v) Manifest.xml:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.android.geo"
          android:versionCode="1"
          android:versionName="1.0">
        <application android:icon="@drawable/icon" >
     
            <activity android:name=".Geolocalisation"
                      android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
     
     
            <activity android:name=".Map"
                      android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.VIEW" />
                    <action android:name="android.intent.action.DEFAULT" />
                </intent-filter>
            </activity>
     
     
        <uses-library android:name="com.google.android.maps"/>
        </application>
        <uses-permission android:name="android.permission.INTERNET" /> 
        <uses-sdk android:minSdkVersion="3" />
     
     
    </manifest>
    Merci de répondre.
    Images attachées Images attachées  

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Shell qui appelle un xterm et lance des commandes
    Par Krispy dans le forum Linux
    Réponses: 6
    Dernier message: 09/03/2006, 17h35
  2. Qui appelle paint() ??
    Par oodini dans le forum 2D
    Réponses: 8
    Dernier message: 25/01/2006, 09h56
  3. [PL/SQL] Trigger qui appelle une procédure
    Par alex6891 dans le forum Oracle
    Réponses: 5
    Dernier message: 19/01/2006, 09h01
  4. [JTable] [FocusListener] Savoir le composant qui appelle
    Par IvanPopov dans le forum Composants
    Réponses: 7
    Dernier message: 27/07/2005, 13h55
  5. Procedures stockées qui appellent un autre ?
    Par Tchinkatchuk dans le forum PostgreSQL
    Réponses: 4
    Dernier message: 09/05/2005, 09h30

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo