android - Button click listener in a fragment -
i know question has been asked thousands of times, have code , have no idea doesn't work. want having button in fragment when clicked, has show toast.
public class myfragment1 extends fragment{ @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // inflate layout fragment view rootview = inflater.inflate(r.layout.fragment_my_fragment1, container, false); button bot = (button)rootview.findviewbyid(r.id.button3); bot.setonclicklistener(new view.onclicklistener(){ @override public void onclick(view view) { toast.maketext(getactivity(), "button clicked", toast.length_long); } }); return rootview; } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); if (getarguments() != null) { mparam1 = getarguments().getstring(arg_param1); mparam2 = getarguments().getstring(arg_param2); } } with code literally nothing happens, doesn't show error message. i've tried different solutions none of them have solved problem
you forgot show toast, kindly show toast using show()
toast.maketext(getactivity(), "button clicked", toast.length_long).show(); there no error, why not getting error messages in logcat. thing not showing toast
see docs more info.
Comments
Post a Comment