Code example for ImageSwitcher

Methods: setImageResource

0
		Gallery g = (Gallery) findViewById(R.id.gallery);
		g.setAdapter(new AdaptadorImagem(this, imagens,new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)));
		g.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
			public void onItemSelected(AdapterView parent, View v, int posicao,long id) {
				// Avisa o ImageSwitcher que a imagem foi alterada 
				imageSwitcher.setImageResource(imagens[posicao]);
			} 
			public void onNothingSelected(AdapterView parent) {
			} 
		}); 
	} 
	// Implementa "ViewSwitcher.ViewFactory" 
	public View makeView() {
		ImageView img = new ImageView(this);
		img.setBackgroundColor(0xFF000000);
		img.setScaleType(ImageView.ScaleType.FIT_CENTER);
		img.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		return img;
	} 
}