générer un TextView automatiquement lors d'un click
Bonsoir,
Je cherche a générer un Textview automatiquement dans mon layout lorsque je click sur un bouton.
Ceci dans le but de créer un caisse enregistreuse, qui afficher donc mon ticket lorsque je click sur chaque produit.
Je joins mon code, si jamais vous avez des idées, je suis preneur.
Merci beaucoup
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
|
// BOUTON TARTAS
Button caja_btn_tartas_limon = findViewById(R.id.caja_btn_tartas_limon);
//ONCLICK BOUTON TARTAS
caja_btn_tartas_limon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
LinearLayout caja_layout_ticket2 = findViewById(R.id.caja_layout_ticket2);
TextView tv_tarta_de_limon = (TextView) new TextView(getApplicationContext());
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams
(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
tv_tarta_de_limon.setLayoutParams(lp);
tv_tarta_de_limon.setText("Tarta de limon");
caja_layout_ticket2.addView(tv_tarta_de_limon);
}
}); |