Establecer diferentes imágenes para diferentes vistas de la galería

I have a listview that consist of 23 rows. When I click any row, it opens a new activity (new screen containing textview and button). When click on the button it opens another screen which is a galleryview. So I have 23 buttons clicked to open 23 galleryviews. I want to set diffrent images in each galleryview.

Aquí está el código que tengo.


                 public class Day_gallery extends Activity {
Integer[] pics = {
    ImageView imageView;
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        Boolean customTitleSupported = requestWindowFeature     
         if (customTitleSupported) { 

         TextView tv = (TextView) findViewById(; 
             tv.setText("day pictures"); 
        Gallery ga = (Gallery)findViewById(;
        ga.setAdapter(new ImageAdapter(this));
        imageView = (ImageView)findViewById(;
        ga.setOnItemClickListener(new OnItemClickListener() {

    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {
    public class ImageAdapter extends BaseAdapter {

        private Context ctx;
        int imageBackground;
        public ImageAdapter(Context c) {
            ctx = c;
        TypedArray ta = obtainStyledAttributes(R.styleable.Gallery);
imageBackground = ta.getResourceId 
       (R.styleable.Gallery_android_galleryItemBackground, 1);


        public int getCount() {
            return pics.length;

        public Object getItem(int arg0) {
            return arg0;

        public long getItemId(int arg0) {
            return arg0;

        public View getView(int arg0, View arg1, ViewGroup arg2) {
            ImageView iv = new ImageView(ctx);
            iv.setLayoutParams(new Gallery.LayoutParams(150,120));
            return iv;



preguntado el 01 de febrero de 12 a las 22:02

2 Respuestas

Have one activity, and you can pass which text to use. Put which day it is in the bundle, and in your next activity, get the integer and then set the text. In this way you will only need 3 activities. One for the ListView, one for the text and buttons, and one to show the gallery. Similar idea from button to gallery.

Esto podría ayudar:

Respondido 02 Feb 12, 04:02

let me put it this way, you dont do addition by saying "1 + 2 = 3" in code, and "1 + 3 = 4" and make 23 different functions all the way up to 23. You just plug in a number to one function. Similar idea: you plug in information for when they are different and keep as much of it the same as possible. As a programmer you need to figure out how to do that- I can't be writing all your code for you. - AJcodez

I reach to this solution as follow :

 if(row.equalsIgnoreCase("first row")){
int[] tempimages = { R.drawable.one_1,R.drawable.one_2,R.drawable.one_3 };  
    tv.setText("first gallery");}

else if
     (row.equalsIgnoreCase("second row")){
int[] tempimages = { R.drawable.one_4,R.drawable.one_5,R.drawable.one_6 };  
    tv.setText("second gallery");} 

and continuing to the rest of rows gallery .

respondido 11 nov., 12:01

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