How make Property with Case Switch?

58 views
Skip to first unread message

kangris

unread,
Sep 12, 2019, 4:03:22 PM9/12/19
to App Inventor Open Source Development
How make Property with Case Switch?

Hi master,

I want make extension,,and want to make
property with fiture case switch.
but i not sure with i to do (-_-)

Please corection this sir,

@DesignerProperty(defaultValue = "cpp", editorType = "int")
@SimpleProperty
public void setLanguage(int lng){
this.lng = lng;

switch(lng) {
case java:
highlighter.setLanguage(highlighter.JAVA);
break;
case python:
highlighter.setLanguage(highlighter.PYTHON);
break;
default:
highlighter.setLanguage(highlighter.CPP);
}
}


Thanks you very much.

Evan Patton

unread,
Sep 13, 2019, 4:17:19 PM9/13/19
to App Inventor Open Source Development
It depends on whether you want to do this in the core system or in an extension. For the core system, you could introduce a new PropertyTypeConstant and define a new editor to do what you want with int cases. For extensions, the only option you have is to have editorType by PropertyTypeConstants.PROPERTY_TYPE_CHOICES and then provide editorArgs with an array of strings naming the values. Instead of taking int as a parameter, take String, and then check the values that way. I believe that dex understands how to do switch statements over strings (added in Java 7), but if that doesn't work you will need to write an if-else chain to check the different incoming values.

Regards,
Evan
Reply all
Reply to author
Forward
0 new messages