Add Helper Block without link with any input?

can i add helper block without add it to any input functions??

Try making a dummy private function with @SimpleFunction, let us know if it works.

2 Likes

I believe, it's not possible at the moment. You must have to attach the helper block with at least one input parameter or as an output type.

1 Like

What would be the purpose of a helper block, which could not be used anywhere?

Taifun

1 Like

What do you really mean by a Helper Block Mahmoud? Is this for the user of your App or for anyone reading your Block Code?

Below uses a single gobal variable to insert comments (notes) anywhere in the code

COMMENT

I tried it, but it is not work

@SimpleFunction
    private int StatusType(@Options(StatusType.class) int statue){
        return statue;
    }

my StatusType class code:


import com.google.appinventor.components.common.OptionList;

import java.util.HashMap;
import java.util.Map;

public enum StatusType implements OptionList<Integer> {
    Active(1),
    Inactive(0)
    ;

    private final int type;
    StatusType(int type){
        this.type = type;
    }

    @Override
    public Integer toUnderlyingValue() {
        return type;
    }
    private static final Map<Integer, StatusType> lookup = new HashMap<>();
    static {
        for(StatusType statusType : StatusType.values()){
            lookup.put(statusType.toUnderlyingValue(), statusType);
        }
    }
    public static StatusType fromUnderlyingValue(Integer statusType){
        return lookup.get(statusType);
    }
}


here is it:

@SimpleFunction(description = "Extracts the specified data field from json array data")
    public YailList ExtractData(Object data, @Options(DataFieldName.class) String fieldName){
        JSONArray jsonArray;
        if (data instanceof JSONArray){
            jsonArray = (JSONArray) data;
        } else if (data instanceof String) {
            jsonArray = new JSONArray((String) data);
        } else {
            OnErrorOccurred("Can't detect data type.", "ExtractData");
            return YailList.makeEmptyList();
        }

        List<Object> list = new ArrayList<>();
        try {
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                list.add(jsonObject.getString(fieldName));
            }
        } catch (JSONException e) {
            OnErrorOccurred(e.getMessage(), "ExtractData");
            return YailList.makeEmptyList();
        }
        return YailList.makeList(list);
    }

my data:

[
  {
    "name": "John Doe",
    "status": 1,
    "info": "Software Developer at XYZ Corp"
  },
  {
    "name": "Jane Smith",
    "status": 0,
    "info": "On maternity leave"
  },
  {
    "name": "Alice Johnson",
    "status": 1,
    "info": "Marketing Manager at ABC Ltd."
  },
  {
    "name": "Bob Brown",
    "status": 1,
    "info": "Project Manager at Tech Solutions"
  },
  {
    "name": "Charlie Davis",
    "status": 0,
    "info": "On vacation"
  }
]

Inactive = 0 and Active = 1

i wanna create Helper Block for Status
my code:


import com.google.appinventor.components.common.OptionList;

import java.util.HashMap;
import java.util.Map;

public enum StatusType implements OptionList<Integer> {
    Active(1),
    Inactive(0)
    ;

    private final int type;
    StatusType(int type){
        this.type = type;
    }

    @Override
    public Integer toUnderlyingValue() {
        return type;
    }
    private static final Map<Integer, StatusType> lookup = new HashMap<>();
    static {
        for(StatusType statusType : StatusType.values()){
            lookup.put(statusType.toUnderlyingValue(), statusType);
        }
    }
    public static StatusType fromUnderlyingValue(Integer statusType){
        return lookup.get(statusType);
    }
}