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:
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2011 Google, All Rights reserved
// Copyright 2011-2012 MIT, All rights reserved
// Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0
package com.google.appinventor.components.runtime;
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.common.YaVersion;
/**
* Button with the ability to detect clicks. Many aspects of its appearance can be changed, as well
* as whether it is clickable (`Enabled`). Its properties can be changed in the Designer or in the
* Blocks Editor.
*/
@DesignerComponent(version = YaVersion.BUTTON_COMPONENT_VERSION,
This file has been truncated. show original
1 Like
Ken
(Ken)
June 25, 2020, 12:04pm
#3
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)
Ken
(Ken)
June 26, 2020, 2:22pm
#7
Anytime you see “new” you need to import it!
import android.view.View.OnClickListener;
1 Like
Ken
(Ken)
June 26, 2020, 2:24pm
#8
Automate_My_Project:
Still getting errors…
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
Ken
(Ken)
June 26, 2020, 9:09pm
#13
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
system
(system)
Closed
July 27, 2020, 6:06am
#15
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.