Android How to set click listener of a button which is from another layout xml file -


mainactivity shows viewpager there 3 layout files:activity_main.xml、card1.xml , card2.xml want view card1.xml , set listener. should do?

i tried using this:

layoutinflater layout=this.getlayoutinflater(); view view=layout.inflate(r.layout.card1, null); button b=(button)view.findviewbyid(r.id.b); 

then set onclicklistener:

b.setonclicklistener(new myclicklistener(0)); 

but useless.

public class myclicklistener implements onclicklistener {      @override     public void onclick(view v) {         switch (v.getid()) {         case r.id.your_btn_id:             // code               break;           }      }  } 

another way can add button click listener in card1.xml fragment class.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -