I'm trying to implement an app with a GridView. I need to load images from an array of ints and when the user clicks on an image, the image changes of background.
But I'm getting an error. The image is changed correctly but when I do scroll, only a white image (No image so there are in res/drawable image) is shown... What is my mistake?
Main.java
public static int [] imagenesIngredientes = {
R.drawable.img_1,
R.drawable.img_2,
...};
gridView.setAdapter(adapter);
gridViewFotos.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
ImageView imagen = ((ViewHolder) v.getTag()).imageItem;
switch (position) {
case 0:
switch (num) {
case 0:
imagen.setImageResource(R.drawable.img_sel_1);
imagenesIngredientes[position] = R.drawable.img_sel_1;
num = 1;
break;
case 1:
imagen.setImageResource(R.drawable.img_1);
imagenesIngredientes[position] = R.drawable.img_1;
numPan = 0;
break;
}
break;
...
}
}
});
img_sel_1.xml
<layer-list xmlns:android="http://ift.tt/nIICcg" >
<item>
<bitmap
android:gravity="center"
android:src="@drawable/img_1" />
</item>
<item>
<shape>
<solid android:color="@color/green" />
</shape>
</item>
Aucun commentaire:
Enregistrer un commentaire