Skip to content

Instantly share code, notes, and snippets.

@akexorcist
Last active August 29, 2015 14:13
Show Gist options
  • Save akexorcist/5a7f23d659533375c425 to your computer and use it in GitHub Desktop.
Save akexorcist/5a7f23d659533375c425 to your computer and use it in GitHub Desktop.
Override OnClick แบบโคตรเหง้าเหล่ากอใน View นั้นๆ
public static void anyMethod(View view, Activity activity) {
final Activity mActivity = activity;
//Set up touch listener for non-text box views to hide keyboard.
if(!(view instanceof EditText)) {
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Do something here
}
});
}
//If a layout container, iterate over children and seed recursion.
if(view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
View innerView = ((ViewGroup) view).getChildAt(i);
anyMethod(innerView, mActivity);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment