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.

(gallery_day.class)

                 public class Day_gallery extends Activity {
Integer[] pics = {
        R.drawable.one_1,
        R.drawable.one_2,
        R.drawable.one_3,
        R.drawable.one_4,
        R.drawable.one_5,
        R.drawable.one_6,
        R.drawable.one_7,
        R.drawable.one_8,
        R.drawable.one_9,
        R.drawable.one_10
   };
    ImageView imageView;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        Boolean customTitleSupported = requestWindowFeature     
                (Window.FEATURE_CUSTOM_TITLE); 
     setContentView(R.layout.day_gallery);  
         if (customTitleSupported) { 
             getWindow().setFeatureInt  
                  (Window.FEATURE_CUSTOM_TITLE,R.layout.custom_title); 

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

    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {
                
                imageView.setImageResource(pics[arg2]);
                
            }
            
        });
        
    }
    
    
    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);

            ta.recycle();
        }

        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.setImageResource(pics[arg0]);
            iv.setScaleType(ImageView.ScaleType.FIT_XY);
            iv.setLayoutParams(new Gallery.LayoutParams(150,120));
            iv.setBackgroundResource(imageBackground);
            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: http://remwebdevelopment.com/dev/a33/Passing-Bundles-Around-Activities.html

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.