Created
September 4, 2015 12:07
-
-
Save FuadBalashov/ef9dc8b609062b631280 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public MyActivity extends Activity implements View.OnClickListener { | |
private View child1; | |
private View child2; | |
onCreate() { | |
// initilize stuff... | |
child1.setOnClickListener(this); | |
child2.setOnClickListener(this); | |
} | |
public boolean onClick(View v) { | |
switch (v.getId()) { | |
case R.id.child_1_id: | |
// logic | |
break; | |
case R.id.child_2_id: | |
// more complex logic, maybe call another method | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Or better yet, if you wire the xml up correctly (and your custom class is an activity) you can just set the
android:onClick
attribute to be "onClick" rather than having to set the on click listeners for the views.