It would be good if you included this information in the first post
Sure why not wait
Good work @Faraz_Firoz!
One suggestion, can you add a 'when Popup1. Dismiss' event in the next version?
Ofcose I also think same I add in my next version
Code was already mentioned
Raw Code :
package com.faraz.popup;
import android.app.Activity;
import android.content.Context;
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.annotations.SimpleFunction;
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.ComponentContainer;
import com.google.appinventor.components.runtime.EventDispatcher;
import com.google.appinventor.components.runtime.AndroidViewComponent;
import android.widget.PopupMenu;
import android.view.View;
import android.widget.AdapterView;
import android.view.MenuItem;
import java.util.List;
@DesignerComponent(
version = 1,
description = "",
category = ComponentCategory.EXTENSION,
nonVisible = true,
iconName = "")
@SimpleObject(external = true)
public class Popup extends AndroidNonvisibleComponent {
private Context context;
private Activity activity;
private PopupMenu popup;
public Popup(ComponentContainer container){
super(container.$form());
this.activity = container.$context();
this.context = container.$context();
}
@SimpleFunction(description = "Creates popup menu")
public void Create(AndroidViewComponent component) {
View view = component.getView();
popup = new PopupMenu(context, view);
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
OnClick (item.getTitle().toString());
return true;
}
});
popup.setOnDismissListener(new PopupMenu.OnDismissListener(){
@Override
public void onDismiss() {
Dismissed();
}
});
}
@SimpleProperty(description = "Add item in popup menu")
public void Add(String name) {
popup.getMenu().add(name);
}
@SimpleFunction(description = "Show popup menu")
public void Show() {
popup.show();
}
@SimpleFunction(description = "Show popup menu")
public void Dismiss() {
popup.dismiss();
}
@SimpleProperty
public void Gravity(int bru){
popup.setGravity(bru);
}
@SimpleEvent(description = "")
public void OnClick (String name) {
EventDispatcher.dispatchEvent(this, "OnClick", name);
}
@SimpleEvent(description = "")
public void Dismissed() {
EventDispatcher.dispatchEvent(this, "Dismissed");
}
@SimpleProperty
public int gravity()
return popup.getGravity();
}
}
That dismiss listener code fo not work you can also compile and check
Most of developers helping in this thread are just wasting their time,if they value the time.
What is this I do not understand what you are saying
Faraz_Firoz, how do you compile Java text into an extension? What instructions do you follow? Can I have links?
Hello @vuk I found these java codes from google and then I open ide.niotron.com and create an extension whose name is popup and there I add thse all java codes and click on compile extension after clicking I got popup.aix file
Many thanks!
Great Extension !!
However, after importing the extension, there is the ADD Block missing
Any idea why?
are you really sure? it is just under onclick
OMG my fault..... I was searching for the green block as shown in Post 1
he updated it lol
1. It is absolutely great.
2. Would it be possible to add BackgroundColor ?
3. Could you please add comment on hexColor it takes ?
Regards and thanks again