android - Toast not showing -
i want show toast on actionitem() function inside. doesn't showing toast.
if call
context context = getapplicationcontext();
before actionitem() app crashes.
import android.content.context; import android.os.bundle; import android.support.v7.app.actionbaractivity; import android.view.menu; import android.view.menuitem; import android.widget.toast; public class showwebviewactivity extends actionbaractivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.show_web_view); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_show_web_view, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. // int id = item.getitemid(); //noinspection simplifiableifstatement // if (id == r.id.action_settings) { // return true; // } switch (item.getitemid()) { case r.id.action_settings: actionitem(); return true; default: return super.onoptionsitemselected(item); } } // context context = getapplicationcontext() makes app crash why?? public void actionitem(){ // toast function should call here. not working context context = getapplicationcontext(); toast.maketext(context, "action setting selected", toast.length_long); } }
it should be,
toast.maketext(context, "action setting selected", toast.length_long).show();
Comments
Post a Comment