Bonjour ,
je fait un projet qui est une application android et je suis débutante ,après l' exécution de mon code le menue que j' ai créer n' apparais pas dans l' application .
voila mon code :

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
public class MainActivity extends AppCompatActivity{
 
 
    public final static String EXTRA_MESSAGE = "MESSAGE";
    private ListView obj;
    DBHelper mydb;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        mydb = new DBHelper(this);
        ArrayList array_list = mydb.getAllPatients();
        ArrayAdapter arrayAdapter=new ArrayAdapter(this,android.R.layout.simple_list_item_1, array_list);
 
        obj = (ListView)findViewById(R.id.listView1);
        obj.setAdapter(arrayAdapter);
        obj.setOnItemClickListener(new OnItemClickListener(){
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
                // TODO Auto-generated method stub
                int id_To_Search = arg2 + 1;
 
                Bundle dataBundle = new Bundle();
                dataBundle.putInt("id", id_To_Search);
 
                Intent intent = new Intent(getApplicationContext(),DisplayPatient.class);
 
                intent.putExtras(dataBundle);
                startActivity(intent);
            }
        });
    }
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }
 
    @Override
    public boolean onOptionsItemSelected(MenuItem item){
        super.onOptionsItemSelected(item);
 
        switch(item.getItemId())
        {
            case R.id.item1:Bundle dataBundle = new Bundle();
                dataBundle.putInt("id", 0);
 
                Intent intent = new Intent(getApplicationContext(),DisplayPatient.class);
                intent.putExtras(dataBundle);
 
                startActivity(intent);
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
 
    public boolean onKeyDown(int keycode, KeyEvent event) {
        if (keycode == KeyEvent.KEYCODE_BACK) {
            moveTaskToBack(true);
        }
        return super.onKeyDown(keycode, event);
    }
 
 
 
}



2eme activité :




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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
public class DisplayPatient extends Activity {
 
    int from_Where_I_Am_Coming = 0;
    private DBHelper mydb ;
 
    TextView nom ;
    TextView prenom;
    TextView age;
    TextView tel;
    TextView maladie;
    TextView degre_maladie;
    TextView commentaire;
    TextView groupe_sang;
    int id_To_Update = 0;
 
 
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // recurepertation de donné saisie dans les edittext
        setContentView(R.layout.activity_display_patient);
        nom           =(TextView) findViewById(R.id.editTextNom);
        prenom        =(TextView) findViewById(R.id.editTextPrenom);
        age           = (TextView) findViewById(R.id.editTextAge);
        tel           = (TextView) findViewById(R.id.editTextTel);
        maladie       = (TextView) findViewById(R.id.editTextMaladie);
        degre_maladie = (TextView) findViewById(R.id.editTextDgre);
        groupe_sang   = (TextView) findViewById(R.id.editTextsang);
 
        commentaire = (TextView) findViewById(R.id.editTextCommentaire);
 
 
// instancir un objet de la classe DBHelper
        mydb = new DBHelper(this);
 
        Bundle extras = getIntent().getExtras();
        if(extras !=null)
        {
            int Value = extras.getInt("id");
 
            if(Value>0){
                //means this is the view part not the add contact part.
                Cursor rs = mydb.getData(Value);
                id_To_Update = Value;
                rs.moveToFirst();
 
                String nomv = rs.getString(rs.getColumnIndex(DBHelper.CONTACTS_COLUMN_NAME));
                String prenomv = rs.getString(rs.getColumnIndex(DBHelper.CONTACTS_COLUMN_PRENOM));
                String agev = rs.getString(rs.getColumnIndex(DBHelper.CONTACTS_COLUMN_AGE));
                String telv = rs.getString(rs.getColumnIndex(DBHelper.CONTACTS_COLUMN_TEL));
                String maladiev = rs.getString(rs.getColumnIndex(DBHelper.CONTACTS_COLUMN_MALADIE));
                String degre_maladiev = rs.getString(rs.getColumnIndex(DBHelper.CONTACTS_COLUMN_DEGRE));
                String groupe_sangv = rs.getString(rs.getColumnIndex(DBHelper.CONTACTS_COLUMN_GROUPE_SANG));
                String commentairev = rs.getString(rs.getColumnIndex(DBHelper.CONTACTS_COLUMN_COMMENTAIRE));
 
                if (!rs.isClosed())
                {
                    rs.close();
                }
                Button b = (Button)findViewById(R.id.button1);
                b.setVisibility(View.INVISIBLE);
 
                nom.setText((CharSequence)nomv);
                nom.setFocusable(false);
                nom.setClickable(false);
 
                prenom.setText((CharSequence)prenomv);
                prenom.setFocusable(false);
                prenom.setClickable(false);
 
                age.setText((CharSequence)agev);
                age.setFocusable(false);
                age.setClickable(false);
 
                tel.setText((CharSequence) telv);
                tel.setFocusable(false);
                tel.setClickable(false);
 
 
                maladie.setText((CharSequence) maladiev);
                maladie.setFocusable(false);
                maladie.setClickable(false);
 
                degre_maladie.setText((CharSequence) degre_maladiev);
                degre_maladie.setFocusable(false);
                degre_maladie.setClickable(false);
 
 
 
                groupe_sang.setText((CharSequence) groupe_sangv);
                groupe_sang.setFocusable(false);
                groupe_sang.setClickable(false);
 
                commentaire.setText((CharSequence) commentairev);
                commentaire.setFocusable(false);
                commentaire.setClickable(false);
            }
        }
    }
 
 
    // Creation d'un menu
 
 
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        Bundle extras = getIntent().getExtras();
 
        if(extras !=null)
        {
            int Value = extras.getInt("id");
            if(Value>0){
                getMenuInflater().inflate(R.menu.display_patient, menu);
            }
 
            else{
                getMenuInflater().inflate(R.menu.main_menu, menu);
            }
        }
        return true;
    }
 
 
    // selection du menue
 
 
    public boolean onOptionsItemSelected(MenuItem item)
    {
        super.onOptionsItemSelected(item);
        switch(item.getItemId())
        {
            case R.id.Edit_Patient:
                Button b = (Button)findViewById(R.id.button1);
                b.setVisibility(View.VISIBLE);
                nom.setEnabled(true);
                nom.setFocusableInTouchMode(true);
                nom.setClickable(true);
 
                prenom.setEnabled(true);
                prenom.setFocusableInTouchMode(true);
                prenom.setClickable(true);
 
                age.setEnabled(true);
                age.setFocusableInTouchMode(true);
                age.setClickable(true);
 
                tel.setEnabled(true);
                tel.setFocusableInTouchMode(true);
                tel.setClickable(true);
 
                maladie.setEnabled(true);
                maladie.setFocusableInTouchMode(true);
                maladie.setClickable(true);
                degre_maladie.setEnabled(true);
                degre_maladie.setFocusableInTouchMode(true);
                degre_maladie.setClickable(true);
 
                groupe_sang.setEnabled(true);
                groupe_sang.setFocusableInTouchMode(true);
                groupe_sang.setClickable(true);
 
                commentaire.setEnabled(true);
                commentaire.setFocusableInTouchMode(true);
                commentaire.setClickable(true);
 
                return true;
            case R.id.Delete_Patient:
 
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setMessage(R.string.deletePatient)
                        .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                mydb.deletePatients(id_To_Update);
                                Toast.makeText(getApplicationContext(), "Deleted Successfully", Toast.LENGTH_SHORT).show();
                                Intent intent = new Intent(getApplicationContext(),MainActivity.class);
                                startActivity(intent);
                            }
                        })
                        .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                // User cancelled the dialog
                            }
                        });
                AlertDialog d = builder.create();
                d.setTitle("Are you sure");
                d.show();
 
                return true;
            default:
                return super.onOptionsItemSelected(item);
 
        }
    }
 
 
 
 
 
//
public void run(View view)
{
    Bundle extras = getIntent().getExtras();
    if(extras !=null)
    {
        int Value = extras.getInt("id");
        if(Value>0){
            if(mydb.updatePatients(id_To_Update, nom.getText().toString(), prenom.getText().toString(), age.getText().toString(), tel.getText().toString(), maladie.getText().toString(), degre_maladie.getText().toString(), groupe_sang.getText().toString(), commentaire.getText().toString())){
                Toast.makeText(getApplicationContext(), "Modifier", Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(getApplicationContext(),MainActivity.class);
                startActivity(intent);
            }
            else{
                Toast.makeText(getApplicationContext(), "n'est pas modifier", Toast.LENGTH_SHORT).show();
            }
        }
        else{
            if(mydb.insertPatients(nom.getText().toString(), prenom.getText().toString(), age.getText().toString(), tel.getText().toString(), maladie.getText().toString(), degre_maladie.getText().toString(), groupe_sang.getText().toString(), commentaire.getText().toString())){
                Toast.makeText(getApplicationContext(), "enregister", Toast.LENGTH_SHORT).show();
            }
 
            else{
                Toast.makeText(getApplicationContext(), "n'est pas enregister", Toast.LENGTH_SHORT).show();
            }
            Intent intent = new Intent(getApplicationContext(),MainActivity.class);
            startActivity(intent);
        }
    }
}
 
 
 
 
 
 
 
 
 
}
menu:


Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
 
    <item android:id="@+id/item1"
        android:icon="@drawable/ajout"
        android:title="@string/Ajouter" >
    </item>
 
 
 
 
</menu>

Code xml : 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
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
 
 
 
    <item
        android:id="@+id/Edit_Patient"
        android:orderInCategory="100"
        android:title="@string/edit"/>
 
    <item
        android:id="@+id/Delete_Patient"
        android:orderInCategory="100"
        android:title="@string/delete"/>
 
</menu>