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 :

Démarrage d’une Activity grâce aux Intents


Sujet :

Android

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Inscrit en
    Mars 2011
    Messages
    140
    Détails du profil
    Informations forums :
    Inscription : Mars 2011
    Messages : 140
    Par défaut Démarrage d’une Activity grâce aux Intents
    Salut à tous

    je veux activer un bouton qui est affiché dans un AlertDialog,pour démarrer une autre activité.

    j'ai trouvé ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    Intent intent = new Intent(HelloItemizedOverlay.this, CLASSE_DESTINATION.class);
    			startActivity(intent);

    il faut que ma classe doit heriter de Activity pour que startActivity() soit activer.

    hors ma classe herite HelloItemizedOverlay herite de ItemizedOverlay.

    voici la classe :

    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
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
     
    package com.android.map;
     
    import java.util.ArrayList;
     
    import android.app.AlertDialog;
    import android.content.Context;
    import android.content.DialogInterface;
    import android.graphics.drawable.Drawable;
    import android.location.LocationListener;
    import android.view.MotionEvent;
    import android.widget.TextView;
    import android.widget.Toast;
     
    import com.google.android.maps.GeoPoint;
    import com.google.android.maps.ItemizedOverlay;
    import com.google.android.maps.MapView;
    import com.google.android.maps.OverlayItem;
     
    public class HelloItemizedOverlay extends ItemizedOverlay {
     
    	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
    	private Context mContext;
     
    	/*public HelloItemizedOverlay(Drawable defaultMarker) {
    		super(boundCenterBottom(defaultMarker));
    		// TODO Auto-generated constructor stub
    	}*/
     
    	public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
    		 // super(defaultMarker);
    		super(boundCenterBottom(defaultMarker));
    		   mContext = context;
    		  // HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(defaultMarker, mContext);
     
    		}
     
    	@Override
    	protected OverlayItem createItem(int i) {
    		// TODO Auto-generated method stub
    		 return mOverlays.get(i);
    	}
     
    	@Override
    	public int size() {
    		// TODO Auto-generated method stub
    		return mOverlays.size();
    	}
    	public void addOverlay(OverlayItem overlay) {
    	    mOverlays.add(overlay);
    	    populate();
    	}
     
    	@Override
    	protected boolean onTap(int index) {
    	  OverlayItem item = mOverlays.get(index);
    	  AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
    	  dialog.setTitle(item.getTitle());
    	  dialog.setMessage(item.getSnippet());  
     
     
    	 dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {  		    	 
    		    	public void onCancel(DialogInterface dialog) {} 
     
    				@Override
    				public void onClick(DialogInterface dialog, int which) {			
     
    				}  
     
    		    });
     
    	 dialog.setPositiveButton("Go", new DialogInterface.OnClickListener() {
     
    		@Override
    		public void onClick(DialogInterface dialog, int which) {
    			// TODO Auto-generated method stub
     
    			/* ---------------- problème
     
    Intent intent = new Intent(HelloItemizedOverlay.this, CLASSE_DESTINATION.class);
    			startActivity(intent);
     
     
    */
     
    		}  		    	 
    		    	//public void onCancel(DialogInterface dialog) {} 
     
     
     
    		    });
     
     
    	  dialog.show();
    	  return true;
    	}
     
     
     
     
    }
    merci

  2. #2
    Membre chevronné
    Profil pro
    Inscrit en
    Mars 2011
    Messages
    322
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2011
    Messages : 322
    Par défaut
    Pourquoi est ce que tu n'utilises pas le contexte que tu as stocké (mContext) pour déclarer ton intent ?

  3. #3
    Expert confirmé

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Par défaut
    Bonjour,

    il faut que ma classe doit hériter de Activity pour que startActivity() soit activé.
    Non il faut que tu ais un Context dans ta Class , tu n'as pas besoin de la faire hérité de Activity.
    Je t'ai mis le lien , de la procédure de startActivity().

    http://developer.android.com/referen...tent.Intent%29

    La solution pour ta class serait donc d'avoir une variable Context ce qui est le cas .

    Donc pour appeler ton startActivity()

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    context.startActivity(intent);

  4. #4
    Membre confirmé
    Inscrit en
    Mars 2011
    Messages
    140
    Détails du profil
    Informations forums :
    Inscription : Mars 2011
    Messages : 140
    Par défaut
    mais j'ai une erreur à cette ligne cette foie ci:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Intent intent = new Intent(HelloItemizedOverlay.this,SiteArchéologiqueDeCarthage.class);

  5. #5
    Membre chevronné
    Profil pro
    Inscrit en
    Mars 2011
    Messages
    322
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2011
    Messages : 322
    Par défaut
    Bonjour,
    Et avec ça tu as toujours l'erreur ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Intent intent = new Intent(mContext,SiteArchéologiqueDeCarthage.class);

  6. #6
    Membre confirmé
    Inscrit en
    Mars 2011
    Messages
    140
    Détails du profil
    Informations forums :
    Inscription : Mars 2011
    Messages : 140
    Par défaut
    merci pour votre aide.
    pas d'erreur maintenant dans cette classe,mais qu'on je click sur le bouton "Go" une erreur qui sur l'emulateur "has stopped unexpectedly". voila la partie du code de HelloItemized

    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
    	@Override
    	protected boolean onTap(int index) {
    	  OverlayItem item = mOverlays.get(index);
    	  AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
    	  dialog.setTitle(item.getTitle());
    	  dialog.setMessage(item.getSnippet());  
     
     
    	 dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {  		    	 
    		    	public void onCancel(DialogInterface dialog) {} 
     
    				@Override
    				public void onClick(DialogInterface dialog, int which) {			
     
    				}  
     
    		    });
     
    	 dialog.setPositiveButton("Go", new DialogInterface.OnClickListener() {
     
    		@Override
    		public void onClick(DialogInterface dialog, int which) {
    			// TODO Auto-generated method stub
     
     
     
     
     
    			Intent intent = new Intent(mContext,GoogleSearch.class);
    			mContext.startActivity(intent);
     
     
     
    		}  		    	 
    		    	//public void onCancel(DialogInterface dialog) {} 
     
     
     
    		    });
     
     
    	  dialog.show();
    	  return true;
    	}
    et la classe GoogleSearch

    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
     
    package com.android.map;
     
    import android.app.Activity;
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.EditText;
    import android.widget.ImageButton;
     
    public class GoogleSearch extends Activity implements View.OnClickListener {
     
    	private ImageButton mImageButton;
    	private EditText mEditText;
     
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.custom_dialog);
    		mImageButton = (ImageButton)findViewById(R.id.imageButton);
    		mEditText = (EditText)findViewById(R.id.editText);
    		mImageButton.setOnClickListener(this);
    	}
     
    	@Override
    	public void onClick(View view) {
    		if (view == mImageButton) {
    			final String requete = "http://www.google.fr/search?q=" + mEditText.getText();
    			Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(requete));
    			startActivity(intent);
    		}
    	}
    }
    avec Custom_dialog est :
    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
     
    <?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="wrap_content"
    	android:layout_gravity="center"
    	android:padding="10px">
     
    	<TextView
    		android:text="Entrez la recherche à effectuer dans le champ ci-dessous puis cliquez sur le bouton"
    		android:layout_width="wrap_content"
    		android:layout_height="wrap_content"
    		android:layout_marginBottom="10px"
    		android:gravity="center_horizontal" />
     
    	<EditText
    		android:id="@+id/editText"
    		android:layout_marginBottom="5px"
    		android:layout_width="fill_parent"
    		android:layout_height="wrap_content" />
     
    	<ImageButton
    		android:id="@+id/imageButton"
    		android:layout_width="wrap_content"
    		android:layout_height="wrap_content"
    		android:src="@drawable/icon"
    		android:layout_gravity="center"></ImageButton>
     
    </LinearLayout>
    merci

  7. #7
    Membre chevronné
    Profil pro
    Inscrit en
    Mars 2011
    Messages
    322
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2011
    Messages : 322
    Par défaut
    Montres nous aussi tes messages sur le logcat

Discussions similaires

  1. indexation de texte grâce aux arbres binaires
    Par méloquenn dans le forum Caml
    Réponses: 1
    Dernier message: 29/10/2007, 09h24
  2. Extraire une partie d'une liste grâce aux index
    Par Matt630 dans le forum Prolog
    Réponses: 7
    Dernier message: 14/12/2006, 10h05
  3. Menu Déroulant activé grâce à un bouton
    Par ero-sennin dans le forum C++Builder
    Réponses: 9
    Dernier message: 07/07/2006, 12h26
  4. Optimiser grâce aux tables temporaires
    Par dcollart dans le forum Langage SQL
    Réponses: 4
    Dernier message: 24/07/2005, 10h11

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