Android arraylist:图片随机化,不匹配正确的描述

时间:2015-02-22 17:06:11

标签: java android string arraylist int

请原谅我。我是java和android开发的新手,请在这里帮助我:这段代码是将图像提供给GridLayout(Worked)并将String []中的右侧decscription附加到GridLayout中的选定图像。这里的问题是:它与每个网格中的图像不匹配,并将它们随机地匹配到错误的描述细节(TextView)。我知道问题出在Math.random()行中。请求我的另一种方式或任何其他建议,我如何能够成功地将我的int []中的图片与字符串[] ........中的相应文本相匹配。

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;
    }_

`

0 个答案:

没有答案