android - How can a widely used custom button track which class its onclick is called from? -


in application, have custom button used in many different custom views. behavior differs depending on view button clicked in, want have 1 @onclick implementation in custom button class takes care of every case in order avoid having similar code in every custom view class.

is there way can determine in @onclick block button clicked from?

it looks like

public class custombutton extends appcompactimagebutton {       //stuff        @onclick       public void onbuttonclick(){           //handles general behavior           //if (clicked customviewa) {               //do stuff           //}     }   }   

and have customviewa has custombutton within it, i'm not sure put in if statement, if that's proper way handle this

you can use tag attribute. in xml layouts, add line

android:tag="viewname" 

to xml button (in code can .settag("viewname"). can modify onclick check tag using this.gettag() , use identify click came from.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -