title: Android overriding onClick(View v) - is there a good solution to use for all buttons in an application
body: <p>As you know we can override a few methods for each type of View that we have created. I am not doing any xml layout code because a lot of stuff changes form at runtime and there are things that are created dynamically so the programmatic solution is the best route for me here. </p>
  
  <p>So to get to the gist of my issue lets say that i have 50 buttons in my Android App. These buttons could potentially be on one Activity but more than likely could span out across multiple screens(Activites). </p>
  
  <p>I have created a button class called CustomButton that overrides the onClick(View view) method. What if some of the buttons are supposed to do some action(lets say they are a part of a linearlayout) and some are part of something like a relative layout and in each relative layout you want to get information about the relative layout that this button resides in(perhaps you what to get information about all the textviews in the same relative layout, etc etc). </p>
  
  <p>One solution of course is that you could get the ID of each button and do a switch(case) or something and depending on what the ID of the button that is returned you can do something. The problem is is i have 50 buttons. What if i had 200? Should i really have to do 200 case checks in my switch statement to figure out what action i need to take? </p>
  
  <p>So i am trying to figure out what information is available to me that i am not aware of that I could use when override the onClick. </p>
  
  <pre><code>   @Override
     public void onClick(View v) {
      // TODO Auto-generated method stub
      if(!getClickInfo()){
          ((CustomButton)v).setText("I clicked the button");
          setClickInfo(true);
      }
      else{
          isClicked = false;
          ((CustomButton)v).setText("This is the button that i want to click");
  
  
      }
  
  }
  </code></pre>
  
  <p>so here is an example. I have passed in the View that represents the button that was clicked and i can change the text of the button as i click on it over and over again. But what if the Button was part of a relative layout? Can i get any other information about other views that also are a part of the same relative layout? What if some buttons i wanted to change the background color of each time i clicked it instead of changing the text? If I have X number of buttons I am trying to stay away from creating X number of IDs -- as i pointed out you could potentially have hundreds of them.</p>
  
  <p>Was wondering if anyone might have any ideas on what would be a better route here than having a potentially unlimited about of case checks inside a switch statement. If i could find out which view the button came from(in my case the button was part of an outer view) then i could do a switch on my views instead of just my buttons - and making my switch statement much less cumbersome and easier to maintain. thanks.  </p>