Skip to content

Instantly share code, notes, and snippets.

@FuadBalashov
Created September 4, 2015 12:07
Show Gist options
  • Save FuadBalashov/ef9dc8b609062b631280 to your computer and use it in GitHub Desktop.
Save FuadBalashov/ef9dc8b609062b631280 to your computer and use it in GitHub Desktop.
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;
}
}
}
@FuadBalashov
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment