Last active
August 29, 2015 14:07
-
-
Save roberto-filho/c240435d69d99fadee40 to your computer and use it in GitHub Desktop.
Bind a "method" to a button through reflection
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
| protected void bindAction(Button btn, final String methodName) { | |
| try { | |
| final Method method = this.getClass().getMethod(methodName, new Class[] {}); | |
| btn.addSelectionListener(new SelectionAdapter() { | |
| @Override | |
| public void widgetSelected(SelectionEvent e) { | |
| try { | |
| method.invoke(GermantechEditor.this, new Object[] {}); | |
| } catch (Exception ex) { | |
| ex.printStackTrace(); | |
| } | |
| } | |
| }); | |
| } catch (Exception e1) { | |
| throw new RuntimeException("Não foi possível encontrar o método \"" + methodName + "\"", e1); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment