Like This :
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.AndroidViewComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.EventDispatcher;
import android.widget.Toast;
//External
@DesignerComponent(version = 1,
category = ComponentCategory.EXTENSION,
description = "Made my YOU",
nonVisible = true,
iconName = "https://icon-icons.com/icons2/1808/PNG/48/code_115247.png")
@SimpleObject(external = true)
public class ExtensionTemplate extends AndroidNonvisibleComponent {
public ExtensionTemplate(ComponentContainer container) {
super(container.$form());
this.container = container;
}
//Write you're code here
@SimpleFunction(description = "Show toast message")
public void ShowToastMessage(String value) {
//YOUR ACTIVITY HERE
Toast.makeText(container.$context(), value, Toast.LENGTH_SHORT).show();
}
}
You need to define the container variable as i said:
or i don't see it
1 Like
Inside your class, under this line
Put it above/under the methods...
You should learn java basics first
Like This Sir
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.AndroidViewComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.EventDispatcher;
import android.widget.Toast;
//External
@DesignerComponent(version = 1,
category = ComponentCategory.EXTENSION,
description = "Made my YOU",
nonVisible = true,
iconName = "https://icon-icons.com/icons2/1808/PNG/48/code_115247.png")
@SimpleObject(external = true)
public class ExtensionTemplate extends AndroidNonvisibleComponent {
public ExtensionTemplate(ComponentContainer container) {
private ComponentContainer container;
super(container.$form());
this.container = container;
}
//Write you're code here
@SimpleFunction(description = "Show toast message")
public void ShowToastMessage(String value) {
//YOUR ACTIVITY HERE
Toast.makeText(container.$context(), value, Toast.LENGTH_SHORT).show();
}
}
Move this before this line, and not under:
Like This Sir :
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.AndroidViewComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.EventDispatcher;
import android.widget.Toast;
//External
@DesignerComponent(version = 1,
category = ComponentCategory.EXTENSION,
description = "Made my YOU",
nonVisible = true,
iconName = "https://icon-icons.com/icons2/1808/PNG/48/code_115247.png")
@SimpleObject(external = true)
public class ExtensionTemplate extends AndroidNonvisibleComponent {
private ComponentContainer container;
public ExtensionTemplate(ComponentContainer container) {
super(container.$form());
this.container = container;
}
//Write you're code here
@SimpleFunction(description = "Show toast message")
public void ShowToastMessage(String value) {
//YOUR ACTIVITY HERE
Toast.makeText(container.$context(), value, Toast.LENGTH_SHORT).show();
}
}
1 Like
I have both extension templete for compile extension and sources for personal builder
1 Like
Sir, I want to ask Can this code be used in all extensions?
private ComponentContainer container;
public ExtensionTemplate(ComponentContainer container) {
super(container.$form());
this.container = container;
This code can be used in all extensions, but you just need to change the class name, as per as your project name, or you will get an error.
This one:
okay i got it, thanks sir
1 Like
package com.extension.Toast1.xoma;
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.AndroidViewComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.EventDispatcher;
//External
import android.widget.Toast;
import android.content.Context;
@DesignerComponent(version = 1,
category = ComponentCategory.EXTENSION,
description = "Simple show toast",
nonVisible = true,
iconName = "https://community.appinventor.mit.edu/user_avatar/community.appinventor.mit.edu/kumaraswamy_b.g/32/13770_2.png")
@SimpleObject(external = true)
public class SimpleToast extends AndroidNonvisibleComponent {
private ComponentContainer container;
private Context context;
public SimpleToast (ComponentContainer container) {
super(container.$form());
this.container = container;
}
@SimpleFunction(description = "Show toast")
public void ShowToast(String message) {
Toast.makeText(container.$context(),message,Toast.LENGTH_SHORT).show();
}
}
This is working for me.
1 Like