Il Forum è consultabile solo in modalità lettura. Per domande o consigli iscriviti al nostro GRUPPO FACEBOOK / COMMUNITY cliccando qui

android problema gallery

Discussione in 'Applicazioni / Multimedia / Giochi' iniziata da Bazz, 20 Set 2012.

  1. Bazz

    Bazz Worker Droid

    Iscritto:
    9 Ago 2012
    Messaggi:
    61
    "Mi Piace":
    1
    ciao
    scusate , solo da poco ho iniziato a lavorare con android ,
    ho il seguente problema :
    ho definito il seguente XML :

    Codice:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <Gallery
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/Gallery2"
            android:layout_width="fill_parent"
            android:layout_marginTop="150dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_gravity="center_horizontal|center_vertical"
            android:layout_height="200dp" />
    
        <ImageView
            android:id="@+id/GalleryView2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
    
    </LinearLayout>
    
    ho fatto la seguente activity :

    Codice:
    public class GalleryActivity2 extends Activity {
    
    	GalleryAdapter2 adapterGallery;	
    	Drawable[] imgs = new Drawable[4];
    	ArrayList<String> images = new ArrayList<String>();
    	String image1; 
    	String image2; 
    	String image3; 
    	String image4; 
    	
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.gallery2);
    
    		Intent intent = getIntent();
    
    		image1 =  intent.getStringExtra("image1");
    		image2 =  intent.getStringExtra("image2");
    		image3 =  intent.getStringExtra("image3");
    		image4 =  intent.getStringExtra("image4");
    		
    		images.add(image1);
    		if (!image2.equals("0")) 
         		images.add(image2);
    		if (!image3.equals("0")) 
         		images.add(image3);
    		if (!image4.equals("0")) 
         		images.add(image4);
    		
    		adapterGallery = new GalleryAdapter2(this, images);
    
    		ImageView imgView = (ImageView) findViewById(R.id.GalleryView2);
    		Gallery gallery = (Gallery) findViewById(R.id.Gallery2);
    
    		gallery.setAdapter(adapterGallery); 
    		
    * * }
    }
    
    e l'adapter è :

    Codice:
    public class GalleryAdapter2 extends BaseAdapter {
    
    	private final Context context ;
    	private final Drawable[] images;
    
        public GalleryAdapter2(Context context, Drawable[] images) {
        	this.context = context;
        	this.images = images;
        	}
        
        	@Override
        	public int getCount() {
        	return images.length;
        	}
        	
        	@Override
        	public Object getItem(int position) {
        	return images[position];
        	}
    
        	@Override
        	public long getItemId(int position) {
        	return images[position].hashCode();
        	}
    
        	@Override
        	public View getView(int position, View convertView, ViewGroup parent) {
        	ImageView imageView;
        	if (convertView == null) {
        	imageView = new ImageView(context);
        	imageView.setScaleType(ScaleType.CENTER_CROP);
        	} else {
        	imageView = (ImageView) convertView;
        	}
        	imageView.setImageDrawable(images[position]);
        	return imageView;
        	}
    
    però nell'acctivity ho il problema di passare il Drawable all'adapter ,
    per favore sapreste come fare ?
    grazie
    ciao