android - How to display a toast message on clicking a button in a fragment? -
first of all, forgive me if silly question because relatively new in field. basically, have activity
contains fragment. fragment has 3 buttons. , when of buttons clicked, wanted display specific toast messages
. used onclick()
method works fine in activity. when use same in fragment, app crashes. please me in regard.name of activity "user.java" , xml file "activity_user.xml". name of fragment "user_home.java" , xml file "user_home_layout.xml".
have attached 2 images, first 1 contains activity , xml file while second 1 contains fragment , sml file.
you need set custom onclicklistener button :
yourbutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { toast.maketext(getactivity(), "your toast text", toast.length_long).show(); } });
Comments
Post a Comment