¿Cómo agregar menuInflater al cambiar a otro formulario?

I am creating an android application called "MyPhonebook". I am having trouble on how to change the menu using menuInflater.
I have two forms, the main.xml and the add_form.xml.
the main form contains a list and an "ADD" menu. when clicking the ADD menu on the main form, it changes the screen to add_form.xml and then changes the menu to SAVE and CANCEL. my problem is, how can I add the SAVE and CANCEL menu on the add_form.xml when the allowable menuinflater used is only one?

How is it done? can anyone help me? to understand it better, here are my codes http://www.mediafire.com/?9zy1t7a99mlz1j3 (download it and paste the extracted folder in your workspace).

preguntado el 01 de febrero de 12 a las 22:02

1 Respuestas

Same as you added the ADD menu on the first activity. in your second activity use the following code and create another xml with your menu for this activity with your save and cancel.

public boolean onCreateOptionsMenu(Menu menu){
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.yoursecondmenu, menu);
    return true;
}

public boolean onOptionsItemSelected (MenuItem item){
    switch (item.getItemId()){
        case R.id.save:
            break;
        case R.id.cancel:
            break;
    }
    return true;
}

Respondido 02 Feb 12, 03:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.