Android: Object information ImageAdapter

2

Because some methods of this ImageAdapter object receive a position as a parameter but at no time I pass it on and if I remove it marks the method error, apart also where I use the position is in getView but I take it as if it were a for, this publication I do it happens to know more about this object. ImageAdapter

public class ImageAdapter extends BaseAdapter {

private Context mContext;
private ArrayList<Bitmap> imagesList;

public ImageAdapter(Context context, ArrayList<Bitmap> imagesList){//recibe como parametros el Contexto y un ArrayList de Bitmaps
    this.mContext = context;//se asgina valores
    this.imagesList = imagesList;//se asgina valores
}//./constructor

@Override
public int getCount() {
    return imagesList.size();//se obtiene el tamanio del array list
}

@Override
public Object getItem(int position) {//debe devolver el objeto real en la posición especificada
    return imagesList.get(position);//obtenemos la posicion
}

@Override
public long getItemId(int position) {//debe devolver el ID de la fila del elemento, pero no es necesario aquí.
    return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView = new ImageView(mContext);

    if (imagesList.size() > 0) {
        imageView.setImageBitmap(imagesList.get(position));
    }
    //caracteristicas del ImageView
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    imageView.setLayoutParams(new GridView.LayoutParams(150, 150));

    return imageView;
}

} //./ class

    
asked by Javier fr 19.12.2016 в 20:22
source

1 answer

0

An Adapter is regularly filled with a list of objects, what it does is get the object in that position to represent it in an element that feeds your adapter.

In this case, the object of the imageList list is being obtained in the position indicated:

@Override
public Object getItem(int position) {//debe devolver el objeto real en la posición especificada
    return imagesList.get(position);//obtenemos la posicion
}

The getItem() and getItemId() methods are methods of the Adapter and this is your definition:

  

getItem (int position) : Gets the data item associated with the   position specified in the data set.

     

getItemId (int position) : Gets the row id associated with the position specified in the list.

I found this tutorial in Spanish that seems complete and related to your last questions:

Tutorial Of Lists And Adapters In Android

    
answered by 19.12.2016 в 20:26