Bonjour,

Je rencontre un problème avec mon application, je possède un viewpager qui renvoi des données d'une base SQLite que l'utilisateur a saisi dans une autre activité.
Je souhaite afficher sur chaque fragment, une seule ligne de ma base. J'ai réussi a créer un fragment à chaque fois qu'une nouvelle ligne est créé mais je ne sais pas comment récupéré chaque colonne de cette ligne et les afficher, j'obtiens toujours la colonne de la dernière ligne sur chaque fragment.
Comment dois-je m'y prendre ? Je n'utilise pas de listViews car le design de mon application ne me le permet pas.
Je vous montre mon code si ça peut vous aider.

Mon adapter :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
public class CarnetAdapter extends FragmentPagerAdapter {
 
    private CarnetDAO carnet;
    private ArrayList<Integer> page_index;
    private Integer nbRow;
    public Context context;
    private Cursor cursor;
 
    public CarnetAdapter(FragmentManager mgr, Context c){
        super(mgr);
        context = c;
        this.set_nbRow();
        page_index = new ArrayList<>();
        for(int i =0; i < this.get_nbr_row(); i++){
            page_index.add(new Integer(i));
        }
    }
 
    @Override
    public int getCount(){
        return this.get_nbr_row();
    }
 
    public void set_nbRow(){
        Integer n = 0;
        carnet = new CarnetDAO(context);
        this.nbRow = carnet.nombre_row();
        carnet.close();
    }
 
    public Integer get_nbr_row(){
        return this.nbRow;
    }
 
    @Override
    public Fragment getItem(int position){
        Integer index = page_index.get(position);
        return affichageReveFragment.newInstance(index.intValue());
    }
 
    @Override
    public int getItemPosition(Object object){
        return PagerAdapter.POSITION_NONE;
    }
 
    public void deletePage(int position){
        page_index.remove(position);
        notifyDataSetChanged();
    }
 
}
Mon fragment (ce que j'ai essayé de faire, et je ne vous mets pas l'initialisation des vues) :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
 
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View rootView = inflater.inflate(R.layout.fragment_affichage_reve, container, false);
 
      /*ici j'ai l'initalisation de toutes mes vues*/
 
 
        CarnetDAO carnetDAO = new CarnetDAO(getContext());
        cursor = carnetDAO.getAllNote();
        getAllData();
        getDreamText();
 
        return rootView;
 
 
    }
 
 
 
 
 
public Carnet get_Dream(int i){
        Carnet car;
        Carnet[] l = mes_reves();
        car = l[i];
        return car;
    }
 
    public Carnet[] mes_reves(){
        CarnetDAO carnet;
        carnet = new CarnetDAO(context);
        cursor = carnet.getAllNote();
        Integer n = cursor.getCount();
        Carnet[] tableau = new Carnet[n];
        boolean hasmore = cursor.moveToFirst();
        int i = 0;
        while (hasmore){
            Carnet a = new Carnet();
            a.setText(cursor.getString(cursor.getColumnIndex("texteCarnetreve")));
            tableau[i] = a;
            hasmore = cursor.moveToNext();
            i++;
        }
        carnet.close();
        return tableau;
    }
 
    int mNum = 0;
    Carnet o = get_Dream(mNum);
    String notes = o.getText();
 
    public void getAllData(){
        CarnetDAO carnet;
        carnet = new CarnetDAO(getContext());
        Cursor note;
 
        notes = String.valueOf(carnet.get_Dream(2));
        lastDream.setText(notes);
}
PS: ici je n'ai pour l'instant essayer d'entrer qu'une seul colonne de ma ligne.

Mon modèle de données :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
public class Carnet {
 
    public Carnet(){
        super();
    }
 
    private int id;
    private String text;
    private String userId;
    private int color;
    private String method;
    private String date;
    private int lucid;
 
    public int getId(){
        return id;
    }
 
    public void setId(int id){
        this.id = id;
    }
 
    public String getText(){
        return text;
    }
 
    public void setText(String text){
        this.text = text;
    }
 
    public int getLucid(){
        return lucid;
    }
 
    public void setLucid(int lucid){
        this.lucid = lucid;
    }
 
    public void setMethod(String method){
        this.method = method;
    }
 
    public String getMethod(){
        return method;
    }
 
    public void setDate(String date){
        this.date = date;
    }
 
    public String getDate(){
        return date;
    }
 
    public void setColor(int color){
        this.color = color;
    }
 
    public  int getColor(){
        return color;
    }
 
}
Mon DAO :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
  public Integer nombre_row(){
        return getAllNote().getCount();
    }
 
    public Carnet get_Dream(Integer id){
        SQLiteDatabase db = this.getReadableDatabase();
        Carnet a = new Carnet();
        String[] columns = {TEXTE_CARNET};
        String selection = ID_CARNET + "=" + id;
        Cursor c = db.query(CARNET_TABLE, columns, selection, null, null, null, ID_CARNET);
 
        if(c!=null){
            if(c.moveToFirst()){
                a.setText(c.getString(c.getColumnIndex(TEXTE_CARNET)));
                c.close();
            }
            return a;
        } else{
            return null;
        }
    }
 
    //recuperer reve
    public Cursor getAllNote(){
        SQLiteDatabase db = this.getWritableDatabase();
        String[] columns = {TEXTE_CARNET, LUCIDITE_CARNET, METHODE_CARNET, AUDIO_CARNET, COULEUR_CARNET, DATE_CARNET};
        this.cursor = db.query(CARNET_TABLE, columns,null, null, null, null, ID_CARNET + " DESC");
        return cursor;
    }
Je pensais à récupérer l'id de la ligne associée au fragment (ce que j'ai essayé de faire avec la méthode "get_Dream(Integer id)" mais pour le coup je ne vois pas comment procéder :/

Merci pour votre aide