dimanche 22 février 2015

Android arraylist: Pictures randomizing and not matching right description

please pardon me. I'm new to java and android development, please help me here: This code is to feed images into GridLayout(Worked) and attach the right decscription in String[] to the selected image in the GridLayout. The Problem here is: It mis-matches the images in each grid and randomly matches them to the wrong description details(TextView). I know the problem is in the Math.random() line. Please my request is for another way or any other suggestion of how I can successfully match the pictures in my int[] to the corresponding texts in string[]........please`





package tan.myplay

import java.util.ArrayList;
import java.util.HashMap;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class BitmapUtils {


int[] mPhotos = {
R.drawable.p1,
R.drawable.p2,
R.drawable.p3,
R.drawable.p4,
R.drawable.two_of_cairo_museum_looted_artefacts_found_in_garden,
};
int numb = mPhotos.length;





String[] mDescriptions = {
" 18th dynasty monarch, better known as King Tut, ruled in the 13th century BC. ",

"2. I took this shot with a pinhole camera ",

"3. I don't remember where or when I took t",

"4. Right the detritus of mankind.",
};

static HashMap<Integer, Bitmap> sBitmapResourceMap = new HashMap<Integer, Bitmap>();




public ArrayList<PictureData> loadPhotos(Resources resources) {
ArrayList<PictureData> pictures = new ArrayList<PictureData>();
for (int i = 0; i < numb; ++i) {
int resourceId = mPhotos[(int) (Math.random() * mPhotos.length)];
Bitmap bitmap = getBitmap(resources, resourceId);
Bitmap thumbnail = getThumbnail(bitmap, 200);
String description = mDescriptions[(int) (Math.random() * mDescriptions.length)];
pictures.add(new PictureData(resourceId, description, thumbnail));
}
return pictures;
}_



`


Aucun commentaire:

Enregistrer un commentaire