bouton pour ajouter une ligne à un tableau
Bonjour à tous,
je suis au commencement du début de la programmation java, et je me suis lancer dans ma 1ere appli basique.
Mais même le basique est forcément compliqué au début.
J'ai donc fait un code qui me permet de générer une ligne avec des infos et des boutons pour une personne.
je souhaite créer un bouton qui ajoute cette même ligne en dessous (en fonction du nombre de personne il pourra y avoir 10 lignes.
peut être que mon code est complétement faux, mais je pense que cela est possible.
c'est mon 1er message, j’espère avoir tout fait correctement.
merci d'avance
.java
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
package com.example.bruno.croix_enfants;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.example.bruno.copines.R;
public class FirstActivity extends ActionBarActivity {
int compteur;
Button ajouter, supprimer, reset, ajouterprenom;
TextView afficheur;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.croix_enfants);
compteur = 0;
ajouterprenom = (Button)findViewById(R.id.baddPrenom);
ajouter = (Button)findViewById(R.id.baddCroix);
supprimer = (Button) findViewById(R.id.blessCroix);
afficheur = (TextView) findViewById(R.id.tvAfficheur);
reset = (Button)findViewById(R.id.breset);
line();
}
private void line() {
ajouter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
compteur++;
afficheur.setText(" a " + compteur + " croix");
}
});
supprimer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (compteur != 0)
compteur--;
afficheur.setText(" a " + compteur + " croix");
}
});
reset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
compteur = 0;
afficheur.setText(" a " + compteur + " croix");
}
});
}
} |
.xml
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TableLayout
android:id="@+id/t1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:id="@+id/tr1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:orientation="horizontal">
<Button
android:id="@+id/baddCroix"
android:layout_width="40dp"
android:layout_height="50dp"
android:text="@string/new_croix" />
<Button
android:id="@+id/blessCroix"
android:layout_width="40dp"
android:layout_height="50dp"
android:text="@string/less_croix" />
<EditText
android:layout_width="150dp"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="@string/prenom"
android:ems="10"
android:id="@+id/editText"
android:layout_column="7"
android:textStyle="bold|italic" />
<TextView
android:id="@+id/tvAfficheur"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:text="@string/nbre_croix"
android:textColor="#f40808"
android:textSize="15sp"
android:textStyle="bold"
android:layout_column="6"
android:layout_marginLeft="0dp" />
<Button
android:id="@+id/breset"
android:layout_width="60dp"
android:layout_height="50dp"
android:text="@string/reset_croix"
android:textSize="12sp"
android:layout_gravity="right" />
</TableRow>
</TableLayout>
<Button
android:id="@+id/baddPrenom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/add_prenom"
/>
</LinearLayout> |