Jump to content

Handler + Boîte de Dialogue


John Easy

Recommended Posts

Bonjour,

Je suis un peu nouveau dans le developpement Android et je bloque sur un bout de code :

- J'ai un Thread qui fait entre autre traitement un handler.sendEmptyMessage(5); et ce Handler va lancer une methode qui affiche une Dialog avec 2 boutons.

Le problème c'est que la Dialog s'affiche, mais tres vite elle disparait sans qu'on ai le temps de cliquer sur l'un des boutons et le thread continu sont traitement.

@Override
public void run() {
                               //bla bla bla
	handler.sendEmptyMessage(5);
                               //blabla
	handler.sendEmptyMessage(0);
}

private Handler handler = new Handler() {

	int progress_value;

	@Override
	public void handleMessage(Message msg) {
		switch (msg.what) {
			case 0: // OK on passe à l'ecran suivant
				Intent i = new Intent(Phone.this, Accueil.class);
				startActivity(i);
				Phone.this.finish();
				break;
                                                               //...
			case 5: // On demande confirmation
				Confirmation conf = new Confirmation();
				conf.DemandConf(Phone.this);
				break;
		}
	}
};

               // le fichier class Confirmation
               public class Confirmation {

                      public void DemandConf(final Context context)
       {
                               //blabla
	final Dialog d = new Dialog(context);
	LayoutParams LP;
	d.setTitle("Confirmer ?");
                               // mise en forme		
	LinearLayout LL_button = new LinearLayout(context);
	LL_button.setOrientation(LinearLayout.HORIZONTAL);
	Button oui = new Button(context);
	Button non = new Button(context);
	LayoutParams LP_button = new android.widget.LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT,1);
	oui.setLayoutParams(LP_button);
	non.setLayoutParams(LP_button);
	oui.setText("oui");
	non.setText("non");
	LL_button.addView(oui);
	LL_button.addView(non);
	LL_general.addView(LL_button);

	d.addContentView(LL_button, new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
	d.show();

	// bouton oui
	oui.setOnClickListener(new OnClickListener() {

		@Override
		public void onClick(View v) {
			//traitement
			d.cancel();
		}
	});
	// bouton non
	non.setOnClickListener(new OnClickListener() {
		@Override
		public void onClick(View v) {
			// traitement
			d.cancel();
		}
	});
}

               }

Quelqu'un sais d'où ça peut venir svp ???

D'avance merci.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...