java - Menu Item To New Activity -
i'm trying send user new activity using menu button, , again. put context, have basic calculator runs when app opened (works perfect right now), want user hit menu button on his/her phone, (two buttons should pop home , tip calculator) when user hits tip calculator should load new activity tipcalculator. if menu button pressed again, same 2 options should appear , home button should bring them basic calculator.
this code calculator.java
@override public boolean oncreateoptionsmenu(menu menu) { super.oncreateoptionsmenu(menu); // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.activity_calculator, menu); menu.add(menu.none,home_menu_id,menu.none,"home"); menu.add(menu.none,second_menu_id,menu.none,"tip calculator"); return true; } @override public boolean onoptionsitemselected(menuitem item) { // todo auto-generated method stub switch(item.getitemid()){ case home_menu_id: intent main = new intent(this,calculator.class); startactivity(main); finish(); return true; case second_menu_id: intent second = new intent(this,tipcalculator.class); startactivity(second); finish(); return true; } return super.onoptionsitemselected(item); }
this code tipcalculator.java
public class tipcalculator extends calculator{ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_tipcalculator); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.activity_tipcalculator, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // todo auto-generated method stub intent main = new intent(this,calculator.class); startactivity(main); finish(); return super.onoptionsitemselected(item); } }
the menu comes fine, , home button refresh home page, tip calculator button gives me force close error , crashes on me.
Comments
Post a Comment