Need help in making a simple extension (return a list)

Hello Everyone,
I am new to extension development.

I am trying to create a block in which I would have set the text in the code editor and I want to return that text.

I tried many ways but I got compilation errors.

show your output

You may use return "TEXT"

These are my Codes in Code Editor.

import android.content.Context;
import android.util.Log;
import com.google.appinventor.components.annotations.;
import com.google.appinventor.components.runtime.
;
import com.google.appinventor.components.common.ComponentCategory;

@DesignerComponent(version = 1, description = "This Extension was created with the AppyBuilder Code Editor.
" +
"Create your own here:
https://editor.appybuilder.com
",
category = ComponentCategory.EXTENSION,
nonVisible = true, iconName = "http://appyBuilder.com/extensions/icons/extension.png")
@SimpleObject(external = true)
public class TextUtilities extends AndroidNonvisibleComponent {
private ComponentContainer container;
/**
* @param container container, component will be placed in
*/
public TextUtilities(ComponentContainer container) {
super(container.$form());
this.container = container;
}

@SimpleFunction(description = "Text")
public void NewLine(String Line = " Text "){
return Line;
}

}

As you can notice in my Codes I have already added it

What are you trying to do with this block.

Hi @Chiru, You cannot return a value from void block.

2 Likes

One of these examples should help:

    @SimpleFunction(description = "Line")
    public String Line(String line){
     return line;
    }
  
    @SimpleFunction(description = "Text")
    public String Text(){
     return "Text";
    }
1 Like

try like this -

import android.content.Context;
import android.util.Log;
import com.google.appinventor.components.annotations.;
import com.google.appinventor.components.runtime.;
import com.google.appinventor.components.common.ComponentCategory;

@DesignerComponent(version = 1, description = "This Extension was created with the AppyBuilder Code Editor.
" +
"Create your own here:
https://editor.appybuilder.com
",
category = ComponentCategory.EXTENSION,
nonVisible = true, iconName = "http://appyBuilder.com/extensions/icons/extension.png 1")
@SimpleObject(external = true)
public class TextUtilities extends AndroidNonvisibleComponent {
private ComponentContainer container;
/**
* @param container container, component will be placed in
*/
public TextUtilities(ComponentContainer container) {
super(container.$form());
this.container = container;
}

@SimpleFunction(description = "Text")
public String NewLine(String Line = " Text "){
return Line;
}

}

here i have did it according to you

I actually didn't understand your Codes.
You are creating a string and returning another one.

so what you want to do ... in your code you are also trying to do same thing.

Hi, @Chiru, can you tell what you want briefly?

Hi @Alpha2020,
I added void by mistake :upside_down_face:

I want to make a block something like this


The Get Text Value should be a text which I will put the value in the Code Editor.

What is the text you want to return

The Text is the Value that I want to add in the Code Editor

import android.content.Context;
import android.util.Log;
import com.google.appinventor.components.annotations.;
import com.google.appinventor.components.runtime.;
import com.google.appinventor.components.common.ComponentCategory;

@DesignerComponent(version = 1, description = "This Extension was created with the AppyBuilder Code Editor.
" +
"Create your own here:
https://editor.appybuilder.com
",
category = ComponentCategory.EXTENSION,
nonVisible = true, iconName = "http://appyBuilder.com/extensions/icons/extension.png 1")
@SimpleObject(external = true)
public class TextUtilities extends AndroidNonvisibleComponent {
private ComponentContainer container;
/**
* @param container container, component will be placed in
*/
public TextUtilities(ComponentContainer container) {
super(container.$form());
this.container = container;
}

    @SimpleFunction(description = "Here") /** Write the description on which I have written "Here"*/
public String NewLine(String Line) 
{
return "Text" /** Write the word you want to return in the "Text" */
}

Paste this in code editor

@Chiru, maybe this can help you

    @SimpleFunction(description = "")
    public String GetName(String name) {
        return name;
    }
1 Like

According to the codes,
The User has to input the value and he will get the same value again but I want to put a value in the Code Editor and return that value (Text)

The Block should appear something like this

Make it like this :

    @SimpleFunction(description = "")
    public String GetName() {
        return "Text";
    }
    @SimpleFunction(description = "")
    public int GetNumber() {
        return 1234;
    }
1 Like

But will it work becuse if we type GetName() and put that bracket empty, will it work?

good question, of course it will work, it will work 100%