Jump to content

Comprendre l'enchainement des écrans


Jorodan

Recommended Posts

Là j'attaque une étape de plus.

Pour l'instant j'affiche tout sur un écran décrit dans mon xml main.

Maintenant je voudrais au clic d'un bouton passer à un autre écran. Quel est la meilleure solution ?

Je crée une nouvelle activité ou il y a une gestion des view que je n'ai pas compris? Ou peut être, je peux "décharger" un xml et en charger un autre ?

Link to comment
Share on other sites

J'avais posé le même genre de question ici:https://www.frandroid.com/forum/viewtopic.php?pid=43284#p43284

Avec le recul de quelques mois de programmation entre les 2, cela me parait évident qu'il faut refaire une activity.

Si tu veux le faire sans seconde activity, je pense que cela peur fonctionner si tu rajoutes à chaque fois les onclicklistener de tes boutons a chaque setContentView(R.layout.xxxxx);

Link to comment
Share on other sites

  • 3 weeks later...

I'm Back!!!

J'essaie de naviguer entre écrans mais je chie...

J'ai un bouton de l'activity launched pour lancer une autre activity.

Activity launched : Accueil

Activity à lancée : AffichageHoraires

Les deux sont déclarées dans le manifeste :

<?xml version="1.0" encoding="utf-8"?>
     package="org.juliendelrio.bussassistant"
     android:versionCode="1"
     android:versionName="1.0">

                 android:label="@string/app_name">











je fais :

startActivity(new Intent(this, AffichageHoraires.class));

Et j'ai ce bug :

11-09 13:34:51.058: WARN/dalvikvm(828): threadid=3: thread exiting with uncaught exception (group=0x4001da28)
11-09 13:34:51.058: ERROR/AndroidRuntime(828): Uncaught handler: thread main exiting due to uncaught exception
11-09 13:34:51.068: ERROR/AndroidRuntime(828): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.juliendelrio.bussassistant/org.juliendelrio.bussassistant.ChoixReseau}: java.lang.NullPointerException
11-09 13:34:51.068: ERROR/AndroidRuntime(828):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401)
11-09 13:34:51.068: ERROR/AndroidRuntime(828):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
11-09 13:34:51.068: ERROR/AndroidRuntime(828):     at android.app.ActivityThread.access$2100(ActivityThread.java:116)
11-09 13:34:51.068: ERROR/AndroidRuntime(828):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
11-09 13:34:51.068: ERROR/AndroidRuntime(828):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-09 13:34:51.068: ERROR/AndroidRuntime(828):     at android.os.Looper.loop(Looper.java:123)
11-09 13:34:51.068: ERROR/AndroidRuntime(828):     at android.app.ActivityThread.main(ActivityThread.java:4203)
11-09 13:34:51.068: ERROR/AndroidRuntime(828):     at java.lang.reflect.Method.invokeNative(Native Method)
11-09 13:34:51.068: ERROR/AndroidRuntime(828):     at java.lang.reflect.Method.invoke(Method.java:521)
11-09 13:34:51.068: ERROR/AndroidRuntime(828):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
11-09 13:34:51.068: ERROR/AndroidRuntime(828):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
11-09 13:34:51.068: ERROR/AndroidRuntime(828):     at dalvik.system.NativeStart.main(Native Method)
11-09 13:34:51.068: ERROR/AndroidRuntime(828): Caused by: java.lang.NullPointerException
11-09 13:34:51.068: ERROR/AndroidRuntime(828):     at org.juliendelrio.bussassistant.ChoixReseau.onCreate(ChoixReseau.java:23)
11-09 13:34:51.068: ERROR/AndroidRuntime(828):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
11-09 13:34:51.068: ERROR/AndroidRuntime(828):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
11-09 13:34:51.068: ERROR/AndroidRuntime(828):     ... 11 more
11-09 13:34:51.088: INFO/Process(76): Sending signal. PID: 828 SIG: 3

Je ne comprends pas :'( Quelqu'un a une idée ?

Link to comment
Share on other sites

bein si tu nous filait la ligne 23 du fichier choixreseau.java on y verrait plus claire

(apprenez à lire les stacktrace non de *ù*ù^*ù)

mais bon sinon tu as oublié le point dans ta déclaration d'activity:

serait plutot

en général eclipse gu***** un peu là dessus.

Edited by popolbx
Link to comment
Share on other sites

(apprenez à lire les stacktrace non de *ù*ù^*ù)

J'allais faire une blague dans ce sens du style "tu as 4 colonnes, la date, l'heure, le code erreur avec le PID et le message détaillé avec le numéro de ligne", mais comme je n'avais pas de piste constructive à indiquer ensuite, je me suis abstenu :)

Link to comment
Share on other sites

Bon ca n'a pas suffit!!

Voici le code qui a l'air de planter... mais qui dans l'activity launched ne plante pas...

La ligne 1 est la ligne 15 du fichier d'origine!

       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);

       // Remplissage de la liste
       Spinner spin = (Spinner)findViewById(R.id.spinner);
       String[] items =  {"Toulouse", "Castres"};
       ArrayAdapter aa = new ArrayAdapter(this, android.R.layout.simple_spinner_item, items);
       aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
       spin.setAdapter(aa);

       // Ecoute bouton
       Button boutonValider = (Button) findViewById(R.id.validation_Ville);
       boutonValider.setOnClickListener(this);

Link to comment
Share on other sites

Toujours pas!!!

Voici mes classes complètes :

Accueil.java

package org.juliendelrio.bussassistant;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Accueil extends Activity implements OnClickListener{
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);

       // Ecoute bouton
       Button boutonValider = (Button) findViewById(R.id.boutonValid);
       boutonValider.setOnClickListener(this);
   }

   public void onClick(View v) {
       startActivity(new Intent(Accueil.this, ChoixReseau.class));
   }
}

ChoixReseau.java

package org.juliendelrio.bussassistant;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;

public class ChoixReseau extends Activity implements OnClickListener{
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);

       // Remplissage de la liste
       Spinner spin = (Spinner)findViewById(R.id.spinner);
       String[] items =  {"Toulouse", "Castres"};
       ArrayAdapter aa = new ArrayAdapter(this, android.R.layout.simple_spinner_item, items);
       aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
       spin.setAdapter(aa);

       // Ecoute bouton
       Button boutonValider = (Button) findViewById(R.id.validation_Ville);
       boutonValider.setOnClickListener(this);
   }

   public void onClick(View v) {
   }
}

J'arrive vraiment pas à voir d'où ca vient!!!

Surtout que la ligne 23 de ChoixReseau me parrait bonne :

        spin.setAdapter(aa);

Link to comment
Share on other sites

Oui oui

<?xml version="1.0" encoding="utf-8"?>
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   >
   android:layout_width="fill_parent" 
   android:layout_height="wrap_content" 
   android:gravity="center_horizontal"
   android:text="Mon assistant transport"
   />
       android:orientation="vertical"
       android:gravity="center"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       >
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content"
           android:gravity="center_horizontal"
           android:text="Veuillez sélectionner un réseau."/>
           android:id="@+id/spinner"
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content"
           android:gravity="center_horizontal"
           />
           android:id="@+id/validation_Ville"
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content"
           android:text="Valider"
           />

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...