Skip to content Skip to sidebar Skip to footer

Android - Handling A Grid

I am trying to make a 2x2 grid of buttons and handle them. Right now I have a relative view activity with four buttons...but my question is: is the best way to do this? Than give e

Solution 1:

First of you you can do

publicclassYourActivityextendsActivityimplementsOnClickListener {...

and then implement the onClick method as

@OverridepublicvoidonClick(View view) {
   switch(view.getId()){
   case R.id.A_UI_Element:
      //do what you need for this elementbreak:
   case R.id.A_Different_UI_Element:
      //do what you need for this elementbreak;
   //continue with cases for each element you want to be clickable
   }
}

Post a Comment for "Android - Handling A Grid"