I like making so that buttons be arranged in the page.
But the number of button depends on the number of datum stored in the database.
To do it, every button has a title stored in the database.
Buttons display well in the page, but I do not manage to make them clickable.
private void displayGridView() {
final Cursor cursor = MessagesBDD.fetchAllMessage();
// The desired columns to be bound
String[] columns = new String[]{MessagesBDD.COL_TITRE,};
final GridView gridview = (GridView) findViewById(R.id.fragboutton);
int[] to = new int[]{R.id.button9,};
final SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.fragment_button, cursor, columns, to, 0);
gridview.setAdapter(adapter);
}
In the OnCreate :
//Création d'une instance de ma classe MessageBDD
MessagesBDD messageBdd = new MessagesBDD(this);
//On ouvre la base de données pour écrire dedans
messageBdd.open();
//Generate ListView from SQLite Database
displayGridView();
//Récupère le fragment permettant d'accèder à la liste des contacts
My Database :
public class Message {
private int id;
private String titre;
private String contenu;
public Message(){}
public Message(String titre, String contenu){
this.titre = titre;
this.contenu = contenu;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitre() {
return titre;
}
public void setTitre(String titre) {
this.titre = titre;
}
public String getContenu() {
return contenu;
}
public void setContenu(String contenu) {
this.contenu = contenu;
}
public String toString(){
return "ID : "+id+"\ntitre : "+titre+"\nContenu : "+contenu;
}
Methode fetchAllMessage :
public static Cursor fetchAllMessage() {
Cursor mCursor = bdd.query(TABLE_MESSAGES, new String[] {COL_ID, COL_TITRE, COL_CONTENU}, null, null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
thanks for your help guys