Need help to code the Click event of the button in Extension

Dear all,

I am an enthusiast in learning app making. I have been building apps for the last two years.
Now i want to build my own extensions which meet my requirements in building apps.

I have made an extension in AppyBuilder to work with a button in runtime.

I created the button and set its text property.

Now i want to run some code on the Click event of the button.
How can i implement the code for this, please help me.

This is the code so far i have done.
WorkingWithButton.java (2.2 KB)

I am exhausted in trying so many codes for this for the last two days.

Eagerly waiting for reply…

Thank you
Hema Srinivas
@AutomateMyProject
India

1 Like

This might help you:

1 Like

myButton.Text(“manas”);

Should be something like:

(TextView)v.Text(“manas”);

1 Like

Still i am getting error…

[javac] H:\Extension Maker Tools\appinventor-sources-master\appinventor\components\src\io\WorkingWithButton\WorkingWithButton.java:41: error: cannot find symbol
[javac]             myButton.setOnClickListener(new View.OnClickListener() {
[javac]                     ^
[javac]   symbol:   method setOnClickListener(<anonymous OnClickListener>)
[javac]   location: variable myButton of type Button

This is my code…
WorkingWithButton.java (1.7 KB)

import below this code to your project

import android.widget.Button;

1 Like

Still getting errors…

If you don’t mind, please compile my code and then suggest me the remedy.
WorkingWithButton.java (1.7 KB)

Anytime you see “new” you need to import it!

import android.view.View.OnClickListener;

1 Like

What errors? This isn’t helpful!

check this error fixed file
WorkingWithButton.java (1.9 KB)

Thank you for your quick response.
Errors are fixed, but button is not visible on the screen.

Dear Ken,

avmcreators02 BetaKoder rectified the errors.

But the Button created is not visible with this code.
WorkingWithButton.java (1.6 KB)

Please look into the code and suggest me the modifications to be done to view the button and perform the click event on it.

Note: One limitation of the current extension component implementation is that it creates non-visible components only (i.e., components that do not show on the designer screen). MIT plans to remove this restriction in future versions of the extension component system.

http://ai2.appinventor.mit.edu/reference/other/extensions.html

You need to add your buttons “View” to an existing “ViewGroup”:

This should help:
AddButton (1).java (2.4 KB)

1 Like

Thank you Ken, it is working.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.