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.

1.activity 2.fragment

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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -