Curso-Android-Desarrollo-de-Aplicaciones-Móviles
Curso-Android-Desarrollo-de-Aplicaciones-Móviles
Curso-Android-Desarrollo-de-Aplicaciones-Móviles
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
CURSO ANDROID<br />
41<br />
public boolean onCreateOptionsMenu(Menu menu) {<br />
MenuInflater inflater = getMenuInflater();<br />
inflater.inflate(R.layout.menu, menu);<br />
return true;<br />
}<br />
A<strong>de</strong>más, requerimos sobrecargar otra función que se dispara cuando el usuario elige alguna <strong>de</strong> las<br />
opciones <strong>de</strong>l menú. Aquí guardaremos en la clase <strong>de</strong> aplicación lo que sea que el usuario haya elegido.<br />
@Overri<strong>de</strong><br />
public boolean onOptionsItemSelected(MenuItem item) {<br />
switch (item.getItemId()) {<br />
case R.id.mmElementApp:<br />
appState.setSelectedOption(APP_VIEW);<br />
break;<br />
case R.id.mmElementBrw:<br />
appState.setSelectedOption(BROWSER_VIEW);<br />
break;<br />
}<br />
return true;<br />
}<br />
Llamando todo <strong>de</strong>s<strong>de</strong> la función onCreate<br />
Dentro <strong>de</strong>l cuerpo <strong>de</strong> la function oCreate inicializamos la variable para nuestra clase <strong>de</strong> aplicación:<br />
appState = ((MyApp)getApplication());<br />
Validamos si el intent lo levantó alguna otra Activity y si viene un -1 en el mensaje mostramos un error:<br />
Intent it = getIntent();<br />
int fromShowElement = it.getIntExtra(POSITION_KEY, 0);<br />
if (fromShowElement == -1) {<br />
Toast.makeText(this, “Error, imposible visualizar el elemento”,<br />
Toast.LENGTH_LONG);<br />
}