Bonjour,

je débute sur Android. J'aimerai faire une ListView donc l'élément sélectionné affiche un menu contextuel. Mon problème est que je n'arrive pas a définir un menu contextuel différent pour chaque élément. Je n'arrive pas à inscrire un id propre à chaque élément dans la ListView (ou recuperer dans la map) et le faire correspondre aux id du menu contextuel pour créer un menu différent à chaque élément de la List View

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
public class TextView extends Activity {
 
	private ListView maListViewPerso;
 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
 
 
        maListViewPerso = (ListView) findViewById(R.id.listviewperso);
 
        ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>();
 
        HashMap<String, String> map;
        map = new HashMap<String, String>();
        map.put("titre", "Admin");
        map.put("description", "Management identification");
        map.put("img", String.valueOf(R.drawable.admin));
        map.put("symbol", String.valueOf(R.drawable.fleche));
        listItem.add(map);
 
        map = new HashMap<String, String>();
        map.put("titre", "Employee");
        map.put("description", "Management Employees");
        map.put("img", String.valueOf(R.drawable.employee));
        map.put("symbol", String.valueOf(R.drawable.fleche));
        listItem.add(map);
 
        map = new HashMap<String, String>();
        map.put("titre", "Expense Line");
        map.put("description", "Expense description");
        map.put("img", String.valueOf(R.drawable.line));
        map.put("symbol", String.valueOf(R.drawable.fleche));
        listItem.add(map);
 
        map = new HashMap<String, String>();
        map.put("titre", "Expense Report");
        map.put("description", "Report of all expenses");
        map.put("img", String.valueOf(R.drawable.expensereport));
        map.put("symbol", String.valueOf(R.drawable.fleche));
        listItem.add(map);
 
        map = new HashMap<String, String>();
        map.put("titre", "Project");
        map.put("description", "Management projects");
        map.put("img", String.valueOf(R.drawable.project));
        map.put("symbol", String.valueOf(R.drawable.fleche));
        listItem.add(map);
 
        SimpleAdapter mSchedule = new SimpleAdapter (this.getBaseContext(), listItem, R.layout.displayitem,
               new String[] {"img", "titre", "description","symbol"}, new int[] {R.id.img, R.id.titre, R.id.description, R.id.symbol});
        maListViewPerso.setAdapter(mSchedule);  
 
     maListViewPerso.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
         public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
 
        	 menu.setHeaderTitle("SubMenu");
             MenuInflater inflater = getMenuInflater();
             inflater.inflate(R.layout.menu, menu);	 
 
         }
     });
 
    }
 
    public boolean onContextItemSelected(MenuItem item){
 
        switch (item.getItemId()) {
        case R.id.employee:
            Toast.makeText(TextView.this, "Delete", Toast.LENGTH_SHORT).show();
            return true;
           case R.id.create01:
               Toast.makeText(TextView.this, "Create", Toast.LENGTH_SHORT).show();
               //setContentView(R.layout.addemployee);
               return true;
           case R.id.delete01:
               Toast.makeText(TextView.this, "Delete", Toast.LENGTH_SHORT).show();
               return true;
           case R.id.edit01:
               Toast.makeText(TextView.this, "Edit", Toast.LENGTH_SHORT).show();
               return true;
           case R.id.list01:
               Toast.makeText(TextView.this, "List", Toast.LENGTH_SHORT).show();
               return true;
           case R.id.project:
               Toast.makeText(TextView.this, "Delete", Toast.LENGTH_SHORT).show();
               return true;
           case R.id.create02:
               Toast.makeText(TextView.this, "Create", Toast.LENGTH_SHORT).show();
               //setContentView(R.layout.addemployee);
               return true;
           case R.id.delete02:
               Toast.makeText(TextView.this, "Delete", Toast.LENGTH_SHORT).show();
               return true;
           case R.id.edit02:
               Toast.makeText(TextView.this, "Edit", Toast.LENGTH_SHORT).show();
               return true;
           case R.id.list02:
               Toast.makeText(TextView.this, "List", Toast.LENGTH_SHORT).show();
               return true;
           case R.id.joinproject02:
               Toast.makeText(TextView.this, "List", Toast.LENGTH_SHORT).show();
               return true;
           case R.id.removeproject02:
               Toast.makeText(TextView.this, "List", Toast.LENGTH_SHORT).show();
               return true;
        }
        return (super.onOptionsItemSelected(item));}
 
 
}
Je ne sais pas si j'ai été assez clair. Excusez moi d'avance :s
Merci pour vos réponses