Code do not work - how do I create a custom adapter?

I create grid view and in that I try to add image and text
but there image is not visible on text is visible
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 java.util.ArrayList;

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 = "")

public void Add(String image, String name){

    String[] myData = {name, image};

    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(context, 17367043, myData);

    grid.setAdapter(arrayAdapter);

    }

}

Help me please

@apsw171118

This is about extension development. At this stage an AIA or blocks will not help to understand the issue

1 Like

Wy making gridview two times?

So what I need to do

I only want to add image in this
It only show tge text image is not visible I only get path of image

So what do you expect from a simple array adapter?

1 Like

I want to know how to add image
Is there any text and image adapter

Build a custom adapter.

Can you tell me how to create

Google it.
However it won't be easy.

There is so many result and actually I do not understand how they create custom adapter

How to create custom adapter
What I try

    import android.os.Bundle;

@SimpleFunction(description = "Add image and name in grid view")

    public void Add(String image, String name){

        Object[] myList = {image, name};

        CustomAdapter customAdapter = new CustomAdapter(context, 17367043, myList);

        grid.setAdapter(customAdapter);

    }

did you create a class first for custom adapter???

No these all are my code I do not create any class How to create tell me please

umm you see the public class yourextensionname extends AndroidNonvisibleComponent {} ?

1 Like

Oh Wait I am sending my whole code

These all are 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 android.view.ViewGroup.LayoutParams;

import android.os.Bundle;

@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 image and name in grid view")

public void Add(String image, String name){

    Object[] myList = {image, name};

    CustomAdapter customAdapter = new CustomAdapter(context, 17367043, myList);

    grid.setAdapter(customAdapter);

}

}

just like you did this make a class

So what is error