Récupérer une variable depuis un onClick
Bonjour,
Je n'arrive pas à récupérer ma variable dans mon onClick. J'ai essayer avec un intent mais ça ne doit pas être la bonne méthode.
Code:
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
|
OnClickListener actioncom = new OnClickListener()
{
public void onClick(View actuelView)
{
Intent thisIntent = getIntent();
String libelle = thisIntent.getExtras().getString("libelle");
Log.i("log_tag", "libelle"+ libelle);
BDD BDD = new BDD(this);
BDD.open();
String ta ="test ta";
Com Com = new Com(libelle, "", tarif1);
Log.i("log_tag", "Com"+ Com);
//On insère
BDD.insertcom(Com);
BDD.close();
Toast.makeText(getApplicationContext(), "Insertion OK", Toast.LENGTH_SHORT).show();
}
};
combut =new Button(this);
Intent intent = new Intent();
intent.putExtra("libelle", libelle);
combut.setOnClickListener(actioncom); |
J'ai essayé aussi de récupéré la valeur du textview mais sa ne marche pas.
Code:
1 2 3 4 5 6
|
//declaration
textviewlibelle = new TextView(this);
//demande dans onclik
String libelle = textviewlibelle.getText().toString(); |
Merci