Potoman Posted August 6, 2010 Share Posted August 6, 2010 Voilà, j'ai un spinner, où sont écris : Département, Région, France. Si l'utilisateur clic sur département, je souhaite qu'alors une nouvelle liste déroulante s'affiche pour lister les différents département. Sauf que quand je fait : public class MyOnItemSelectedListener extends Activity implements OnItemSelectedListener { public int etat = 0; public RechercheOrganisme essai; public MyOnItemSelectedListener (RechercheOrganisme bis){ essai = bis; } @Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { onItemSelected(parent, view, pos, id, essai); } public void onItemSelected(AdapterView<?> parent, View view, int pos, long id, RechercheOrganisme essai) { Toast.makeText(parent.getContext(), "The planet is " + parent.getItemAtPosition(pos).toString(), Toast.LENGTH_SHORT).show(); //Intent monIntent = new Intent(this,ListeRegion.class); //startActivity(monIntent); //Toast.makeText(parent.getContext(), "pos : " + pos + " ", Toast.LENGTH_SHORT).show(); etat = pos; essai.choixLocalisation = etat; if (etat == 2){ Intent monIntent = new Intent(parent.getContext(),ListeRegion.class); startActivity(monIntent); } } public void onNothingSelected(AdapterView<?> parent) { // Do nothing. } } Mon code plante quand je tombe sur le choix 2 ( département ), l'application ne veut pas me créer cette liste de département. Alors qu'elle se créé très bien si je mets un simple bouton. Voici le code qui lance le spinner : package org.example.RootISM11; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.ArrayAdapter; import android.widget.Spinner; import android.widget.Toast; public class RechercheOrganisme extends Activity implements OnClickListener { int choixLocalisation = 0; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.rechercheorganisme); Spinner spinner = (Spinner) findViewById(R.id.spinner); ArrayAdapter adapter = ArrayAdapter.createFromResource( this, R.array.localisations_array, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); //Intent monIntent = new Intent(this,ListeRegion.class); //startActivity(monIntent); MyOnItemSelectedListener moche = new MyOnItemSelectedListener(this); spinner.setOnItemSelectedListener(moche); } } Bon, comme je débute sur Android... Vous moquez pas trop de moi ^^ Merkiki Link to comment Share on other sites More sharing options...
Potoman Posted August 7, 2010 Author Share Posted August 7, 2010 Ou sinon, je me demandai aussi : Mon splinner va modifier une variable d'état, un int plus précisément, dans l'activité qui l'appel. Soit : choixLocalisation dans RechercheOrganisme. Ce que je peut donc aussi faire, et c'est ce qui me semblerai le plus judicieux, c'est d'écouter cet objet, et à chaque instant qu'une de ses variable change, je pourrai appeler une tiers fonction pour appeler enfin ma liste déroulante. Oui mais voilà, comment fait on pour écouter le changement de contenu d'une variable d'un objet. Faut t-il faire un "implements xxxxxxx" dans la déclaration de l'objet "RechercheOrganisme" ? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.