Ich muss meine adapter
Anzeige Bilder machen, so dass ich ein Array von ganzen Zahlen und setzen Sie es eine ID von Bildern, aber wenn ich es an den Array-Adapter-Konstruktor gesendet bekomme ich einen Fehler, weil der Typ Integer
. Wie könnte ich dieses Problem lösen?Array Adapter Constructor
der Fehler erscheint hier Super (Kontext, Ressource, Objekte);
Meine GridViewAdapter Klasse:
package com.example.hima.moviesapp;
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 java.util.ArrayList;
/**
* Created by Hima on 3/23/2016.
*/
public class GridViewAdapter extends ArrayAdapter<String> {
private Context mContext;
private int layoutResourceId;
private ArrayList<Integer > mGridImages = new ArrayList<Integer>();
public GridViewAdapter(Context context, int resource, ArrayList<Integer> objects) {
//the error apear here!!
super(context,resource, objects);
this.mContext=context;
this.layoutResourceId=resource;
this.mGridImages=objects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
ImageView image;
if(row == null){
LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
image= (ImageView)row.findViewById(R.id.movieImage);
row.setTag(image);
}
else{
image = (ImageView)row.getTag();
}
int temp = mGridImages.get(position);
image.setImageResource(temp);
return row;
}
}
MyMainFragment Klasse:
package com.example.hima.moviesapp;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import java.util.ArrayList;
/**
* A placeholder fragment containing a simple view.
*/
public class GridViewFragment extends Fragment {
int[] DummyImages = {R.drawable.first,R.drawable.second,R.drawable.third,R.drawable.fourth,
R.drawable.fifth,R.drawable.sixth};
public GridViewFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
ArrayList<Integer>DummyPosters= new ArrayList<>();
for(int i=0;i<DummyImages.length;i++) {
DummyPosters.add(DummyImages[i]);
}
GridView gridView = (GridView) rootView.findViewById(R.id.gridView);
gridView.setAdapter(new GridViewAdapter(getActivity(),R.id.movieImage,DummyPosters));
return rootView;
}
}
Änderungstyp von ArrayAdapter zu ArrayAdapter –