Why my code do not work

My code

package com.faraz.gridlayout;

import com.google.appinventor.components.annotations.*;

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

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.runtime.HVArrangement;

import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;

import com.google.appinventor.components.runtime.ComponentContainer;

import android.view.View;

import android.widget.GridView;

import android.widget.FrameLayout;

import android.widget.ArrayAdapter;

import android.content.Context;

import java.util.List;

import android.view.ViewGroup.LayoutParams;

@DesignerComponent(

        version = 1,

        description = "",

        category = ComponentCategory.EXTENSION,

        nonVisible = true,

        iconName = "https://res.cloudinary.com/df3qkgfyp/image/upload/v1623985468/FC_tl2sy2.png")

@SimpleObject(external = true)

public class GridLayout extends AndroidNonvisibleComponent {

    private GridView grid;

    private Context context;

    public GridLayout(ComponentContainer container){

        super(container.$form());

        this.context = container.$context();

        grid = new GridView(context);

    }

@SimpleFunction(description = "Creates grid in the arrangement that you give")

public void Create(HVArrangement arrangement) {

    View view = arrangement.getView();

    grid = new GridView(context);

    FrameLayout frameLayout = (FrameLayout) view;

    frameLayout.addView(grid, new FrameLayout.LayoutParams(1, 1));

}

@SimpleFunction(description = "Add data in grid")

public void Add(List list){

    ArrayAdapter arrayAdapter = new ArrayAdapter(context, 17367043, list);

    grid.setAdapter(arrayAdapter);

}

}

How I use

Error
When I click button nothing happen.

1 Like

You set the width and height to 1px.
Try: LayoutParams.WRAP_CONTENT or LayoutParams.MATCH_PARENT

1 Like

Oh that's -1, -1 wright

1 Like

Yes, -1 or -2.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.