bonjours a tous,
en fait je souhaite mettre a jour ma liste view, j'utilise le notifyDataSetChanged() mais je ne sais pas pourquoi ca ne marche pas!!
je dispose de deux activité:
la première affiche la liste des clients disponible dans la base (ca marche)
la deuxième permet de rajouter des clients dans la liste, dans mon StartActivityForResult(), je reçoi bien le client a afficher, j'utilise le notifyDataSetChanged() pour mettre a jour mon adapter mais ca ne fonctionne pas.
quelqu'un aura la réponse s'il vous plait??
voici une partie de mon code:
et voici 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 public class ListClientActivity extends ListActivity { private static final int MENU_AJOUT_CLIENT = 0; private static int CODE_RETOUR = 1; private TextView titre; private ArrayList<String> listclient = null; private int position_client; ListClientAdapter clientadapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.listclient); titre = (TextView) findViewById(R.id.SectionName); titre.setText(R.string.LISTE_CLIENTS); ClientDataBase db = new ClientDataBase(this); listclient = db.getAllClientsName(); db.close(); setListAdapter(new ListClientAdapter(this, listclient)); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(requestCode == CODE_RETOUR && resultCode == RESULT_OK){ String nomEntreprise = data.getStringExtra("nom_Entreprise"); listclient.set(position_client, nomEntreprise); clientadapter = new ListClientAdapter(this, listclient); clientadapter.notifyDataSetChanged(); } } @Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); position_client = position; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case MENU_AJOUT_CLIENT: Intent intent = new Intent(this,NewClientActivity.class); //startActivity(intent); startActivityForResult(intent, CODE_RETOUR); break; } return super.onOptionsItemSelected(item); }
merci d'avance.
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 package fr.sii.dsi.views; import java.util.ArrayList; import fr.sii.dsi.R; import fr.sii.dsi.webservice.Client; import android.app.Activity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.LinearLayout; import android.widget.TextView; public class ListClientAdapter extends BaseAdapter { Activity context; ArrayList<String> clients; public ListClientAdapter(Activity context,ArrayList<String> clients){ this.context = context; this.clients = clients; } @Override public int getCount() { return clients.size(); } @Override public Object getItem(int position) { return position; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { LinearLayout monlayout; Myholder myholder; if(convertView == null){ LayoutInflater inflater = context.getLayoutInflater(); monlayout = (LinearLayout) inflater.inflate(R.layout.modellistclient, null); myholder = new Myholder(); monlayout.setTag(myholder); myholder.label = (TextView) monlayout.findViewById(R.id.label); } else{ monlayout = (LinearLayout)convertView; myholder = (Myholder) monlayout.getTag(); } myholder.label.setText(clients.get(position)); return monlayout; } private class Myholder{ TextView label; } }
Partager