Bonjour,

Je dois créer une application de gestion de tâches. Pour ce faire, nous devons utiliser une BDD SqlLite et un GridView (consigne du prof)

Cependant, je rencontre un problème dans le rafraichissement de la Grid avec le custom Adapter alors que je n'ai aucun problème avec un ArrayAdapter classique. En effet, il a bien un rafraichissement qui s'exécute mais l'image et le texte ne correspondant pas à l'objet ( lorsque je fais un clique dessus j'ai bien le bon objet)

Voici le code de 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
 
 
public class CustomAdaptater extends BaseAdapter {
 
    ArrayList<Tache> ListeDesTaches = new ArrayList<Tache>();
    private TextView tv ;
    private ImageView img;
    Context context;
    int [] imageId;
    private static LayoutInflater inflater;
 
 
 
    public CustomAdaptater(Context myContext, ArrayList<Tache> monGestionnaireTache) {
 
        // TODO Auto-generated constructor stub
        //this.ListeDesTaches= new ArrayList<Tache>();
        ListeDesTaches =monGestionnaireTache;
        context=myContext;
        inflater = LayoutInflater.from(myContext);
 
    }
 
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return ListeDesTaches.size();
    }
 
    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return ListeDesTaches.get(position);
    }
 
    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return ListeDesTaches.get(position).getId();
    }
 
    public class Holder
    {
        TextView tv;
        ImageView img;
    }
 
 
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        Holder viewHolder;
 
 
        if (convertView == null) {
 
            viewHolder= new Holder();
            convertView = inflater.inflate(R.layout.myitemgid, null);
            viewHolder.tv = (TextView) convertView.findViewById(R.id.textView1);
            viewHolder.img = (ImageView)convertView.findViewById(R.id.imageView1);
            viewHolder.tv.setText(ListeDesTaches.get(position).toString());
            viewHolder.img.setImageResource(ListeDesTaches.get(position).getId_image());
 
            convertView.setTag(viewHolder);
 
        } else {
            viewHolder = (Holder) convertView.getTag();
        }
 
        return convertView;
    }
 
    public void RefreshData() {
 
        this.notifyDataSetChanged();
    }
Mon mainActivity :
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
 
private Spinner monSpinner;
    private ArrayList<String> MaListe;
    private ArrayList<String> listeDesTache;
    public GestionnaireTache monGestionnaireTache;
    private Button monButton;
    private GridView ListeTacheGrid;
    private ListView ListTache;
    //private CustomAdaptater GridViewArrayAdapter;
    private ArrayAdapter<Tache> GridViewArrayAdapter;
    private Context context;
    private DatabaseHandler db ;
 
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
 
 
        context = this;
        monSpinner = (Spinner) findViewById(R.id.monSpinner);
        monButton = (Button) findViewById(R.id.monButton);
        ListeTacheGrid = (GridView) findViewById(R.id.ListeTacheGrid);
        monGestionnaireTache = new GestionnaireTache();
 
 
 
 
        db = new DatabaseHandler(context);
 
        try {
            monGestionnaireTache.addAllTache(db.getAllTache());
        } catch (ParseException e) {
            e.printStackTrace();
        }
 
 
        monSpinner.setPrompt("Choisissez votre catégorie");
 
        //GridViewArrayAdapter = new CustomAdaptater(this,monGestionnaireTache.getListeTache());
        GridViewArrayAdapter = new ArrayAdapter<Tache>(this,android.R.layout.simple_list_item_1, monGestionnaireTache.getListeTache());
 
        ListeTacheGrid.setAdapter(GridViewArrayAdapter);
 
monSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                int item = monSpinner.getSelectedItemPosition();
 
                Context context = getApplicationContext();
                String text = monSpinner.getItemAtPosition(item).toString() + " has been selected";
                int duration = Toast.LENGTH_SHORT;
 
                RefreshGrid(monSpinner.getItemAtPosition(item).toString());
 
                Toast toast = Toast.makeText(context, text, duration);
                toast.show();
 
            }
 
            @Override
            public void onNothingSelected(AdapterView<?> parent) {
 
            }
        });
 
@Override
    protected void onResume() {
        super.onResume();
 
 
        try {
            monGestionnaireTache.clear();
            monGestionnaireTache.addAllTache(db.getAllTache());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        //GridViewArrayAdapter.RefreshData();
        GridViewArrayAdapter.notifyDataSetChanged();
 
 
 
    }
 
    public  void RefreshGrid(String categorie)
    {
        if (categorie.equals("TOUS"))
        {
            monGestionnaireTache.clear();
            try {
                monGestionnaireTache.addAllTache(db.getAllTache());
            } catch (ParseException e) {
                e.printStackTrace();
            }
 
            //GridViewArrayAdapter.RefreshData();
 
            GridViewArrayAdapter.notifyDataSetChanged();
        }
        else
        {
            monGestionnaireTache.clear();
            try {
                monGestionnaireTache.addAllTache(db.getAllTacheWithCategorie(categorie));
            } catch (ParseException e) {
                e.printStackTrace();
            }
 
            GridViewArrayAdapter.notifyDataSetChanged();
 
            //GridViewArrayAdapter.RefreshData();
        }
    }
Pouvez-vous m'aider ?