¿Cómo puedo crear una matriz de imágenes?

I want to create an array which contains number of images. Later on I have to use that array in a loop in my code. Can anyone suggest if I can create an array of images.?

preguntado el 27 de noviembre de 13 a las 06:11

what you tried ? paste some code first -

4 Respuestas

define a array of image id like this

int[] p = {R.drawable.image1, R.drawable.image2....}

now for different condition use member of this array like

yourbutton.setBackgroundResource(p[0])  // or p[1]

or you can use ENUM to make it more readable..

respondido 27 nov., 13:06

this will solve you problem:

int imageArray[] = new int[number_of_images];
for (int i = 0; i < numImages; i++)
imageArray[i] = getDrawableId(getApplicationContext(),"R.drawable." + image_names[i]);

respondido 27 nov., 13:06

You can define an array of image filenames :

String fileNames[] = {"temp.jpg", "sample_img28.jpg", "normImg.jpg", "drawing.png", "film.png"};

and add those in MeidaTracker while initializing the application

MediaTracker tracker = null;    

public void init() {

    tracker = new MediaTracker(this);
    for(int i = 0; i < fileNames.length; i++) {
        System.out.println(" path :"+this.getCodeBase());
        image[i] = getImage(this.getCodeBase(),fileNames[i]);
        image[i] = image[i].getScaledInstance(256, 256, Image.SCALE_SMOOTH);
        tracker.addImage(image[i], i);
    }
    try {
        tracker.waitForAll();
    }
}

respondido 27 nov., 13:06

Create your own customImageAdapter extending ArrayAdapter.
Sample code for your arrayAdapter:

public class CustomImageAdapter extends BaseAdapter{
    private Activity activity;
    private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater=null;
    public ImageLoader imageLoader; 

    public CustomImageAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
    }

    public int getCount() {
        return data.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }
 // if you want to display the image modify the content according o your need
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.list_row, null);

        ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image);//thumb image


        return vi;
    }

respondido 27 nov., 13:06

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.