0

我正在尝试使用自定义 GridView ,但出现此错误:

Multiple markers at this line
    - Cannot instantiate the type GalerieAdapter
    - Line breakpoint:Galerie [line: 48] - 
     onCreate(Bundle)
    - Cannot instantiate the type GalerieAdapter

第 48 行,显示错误:

customGridAdapter = new GalerieAdapter(this, R.layout.galerie_row, gridArray);

这是 Galerie.java:

package com.descoper.rom;

import java.util.ArrayList;


import android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.widget.GridView;
import android.widget.ListAdapter;



public class Galerie<GalerieAdapter> extends Activity {
    GridView gridView;
    ArrayList<Item> gridArray = new ArrayList<Item>();
     GalerieAdapter customGridAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.galerie);

        //set grid view item
        Bitmap homeIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.ro);
        Bitmap userIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.ro);

        gridArray.add(new Item(homeIcon,"Home"));
        gridArray.add(new Item(userIcon,"User"));
        gridArray.add(new Item(homeIcon,"House"));
        gridArray.add(new Item(userIcon,"Friend"));
        gridArray.add(new Item(homeIcon,"Home"));
        gridArray.add(new Item(userIcon,"Personal"));
        gridArray.add(new Item(homeIcon,"Home"));
        gridArray.add(new Item(userIcon,"User"));
        gridArray.add(new Item(homeIcon,"Building"));
        gridArray.add(new Item(userIcon,"User"));
        gridArray.add(new Item(homeIcon,"Home"));
        gridArray.add(new Item(userIcon,"xyz"));


        gridView = (GridView) findViewById(R.id.gridView1);
        customGridAdapter = new GalerieAdapter(this, R.layout.galerie_row, gridArray);
        gridView.setAdapter((ListAdapter) customGridAdapter);
    }

}

这是 GalerieAdapter.java:

package com.descoper.rom;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;


public class GalerieAdapter extends ArrayAdapter<Item> {
    Context context;
    int layoutResourceId;
    ArrayList<Item> data = new ArrayList<Item>();

    public GalerieAdapter(Context context, int layoutResourceId,
            ArrayList<Item> data) {
        super(context, layoutResourceId, data);
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        this.data = data;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        RecordHolder holder = null;

        if (row == null) {
            LayoutInflater inflater = ((Activity) context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);

            holder = new RecordHolder();
            holder.txtTitle = (TextView) row.findViewById(R.id.item_text);
            holder.imageItem = (ImageView) row.findViewById(R.id.item_image);
            row.setTag(holder);
        } else {
            holder = (RecordHolder) row.getTag();
        }

        Item item = data.get(position);
        holder.txtTitle.setText(item.getTitle());
        holder.imageItem.setImageBitmap(item.getImage());
        return row;

    }

    static class RecordHolder {
        TextView txtTitle;
        ImageView imageItem;

    }
}

非常感谢 !

4

0 回答 0