How can i set the onclick(); event of a button?

i want to set a button's onclick property.

here is my code

@SimpleFunction(description = "blah blah blah")
    public String Getcomponent(AndroidViewComponent component){

i want to know what to code after this.

please help me

 public class MyActivity extends Activity {
     protected void onCreate(Bundle savedInstanceState) {


         final Button button = findViewById(;
         button.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                 // Code here executes on main thread after user presses button

sorry, but i didn't understand.

please complete my code
it's my humble request

Add a onclick listener to it

1 Like
@SimpleFunction (description = "blah blah blah")
public void GetComponent(AndroidViewComponent component){
View view = component.getView();
         view.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                 // Your On Click Code

one more question , can i create public interfaces .

Please ask new questions in a new topic


okay, thanks

Unfortunately you can't access onCreate() and use XML here.
Even if you somehow use onCreate() then you can expect to get a runtime error.


can we use something else at the place of onCreate().

For Click functionality there is no need, this is the code you need:

1 Like

any imports needed ??

Yes, anytime your see "new insert word here" you'll need to import it.

1 Like

This may help as well: