You can do it like this:
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.menueditar) {
Intent iedicao = new Intent(MainActivity.this, paginadeedicao.class);
startActivity(iedicao);
MainActivity.this.finish();
return true;
}
}
return super.onOptionsItemSelected(item);
}
where:
Intent iedicao = new Intent(MainActivity.this, paginadeedicao.class);
You create a new Intent with the name in this case from mainActivity (current activity) to paginated.class (which is another code page)
You can also send parameters with the extra put:
iedicao.putExtra("pagina", page);
has to come before startActivity.
You’re inflating the menu?
//coloca os ícones no menu
@Override
public boolean onMenuOpened(int featureId, Menu menu) {
if(featureId == Window.FEATURE_ACTION_BAR && menu != null){
if(menu.getClass().getSimpleName().equals("MenuBuilder")){
try{
Method m = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);
m.setAccessible(true);
m.invoke(menu, true);
} catch(NoSuchMethodException e){
} catch(Exception e){
throw new RuntimeException(e);
}
}
}
return super.onMenuOpened(featureId, menu);
}
//cria todos os menus
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
onMenuOpened(Window.FEATURE_ACTION_BAR, menu);
return true;
}
//seta as opções de função dos itens do menu
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.menueditar) {
startActivity(new Intent(MainActivity.this, edicao.class));
MainActivity.this.finish();
return true;
}
}
return super.onOptionsItemSelected(item);
}
that
startActivity(new Intent(MainActivity.this, edicao.class));
is equal to that
Intent iedicao = new Intent(MainActivity.this, paginadeedicao.class);
startActivity(iedicao);
just call the Internet instead of the Toast
– Joannis
@Joannis, I did and it didn’t work out, man. I’ve tried this before. You can put the code in how you did it ?
– Artur Mafezzoli Júnior
postei, see if it works!
– Joannis
@Joannis, I did as you showed me there. Error: Error:(98, 2) error: reached end of file while Parsing
– Artur Mafezzoli Júnior
try now, we missed Return
– Joannis