android - Onclick with Fragment , there's no error but it doesn't work -


public class frag2 extends fragment {      button btn_service;      @override      public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {          view = inflater.inflate(r.layout.fragment2, container, false);         ((edittext) good.findviewbyid(r.id.edittext)).settext("edit text test");           final view v = inflater.inflate(r.layout.fragment2, container,                 false);          btn_service = (button) v.findviewbyid(r.id.btn);         btn_service.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view view) {                 snackbar.make(view, "test snackbar button", snackbar.length_long)                         .setaction("action", null).show();             }          });         return good;     } 

i want know how code onclick fragment layout. i'm novice in android coding. may ask wrong question.

you creating 2 separate views good , v need good , v there , doing nothing because good the actual fragment view displayed in activity (due return good) need bind action child of good

from inflate (int resource, viewgroup root, boolean attachtoroot)

inflate new view hierarchy specified xml resource.

//final view v = inflater.inflate(r.layout.fragment2, container, //        false);  btn_service = (button) good.findviewbyid(r.id.btn); //                     ^^^^ 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -