java - How can I call to a button Event Listener. even is not clicked? -
i have button event listener actions inside work good. want execute event listener don't press button mean execute normal method. because don't want copy , paste same code. how can it?
thank you!
anonymous classes create have access methods in surrounding class. i'm assuming have activity code this:
button button = (button) findviewbyid(r.id.mybutton); button.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { // stuff here } });
instead, add method activity, private void dobuttonstuff()
. set onclicklistner
onclick
method looks this:
public void onclick(view v) { dobuttonstuff(); }
now can call dobuttonstuff()
without having trigger listener.
alternatively programatically click button:
button button = ... button.performclick()
this fires attached onclicklistener, , makes , sound button clicked. think extracting code method sounds better solution situation though.
Comments
Post a Comment