Programación y Desarrollo para Android Subforo exclusivo para temas de programación de software para PDAs y desarrollo de aplicaciones, interfaces, etc bajo Android

Respuesta
 
Herramientas
  #1  
Viejo 13/01/14, 11:52:06
Array

[xs_avatar]
Napster87 Napster87 no está en línea
Miembro del foro
 
Fecha de registro: may 2013
Mensajes: 74
Tu operador: Movistar

Imageswitcher con sqlite,cursor array?

Hola,estoy tratanto de mostrar en un imageswitcher imagenes desde la bd,concretamente tengo un campo string donde almaceno la uri de las fotos que se encuentra en drawables.He solucionado parte pero el problema esta en pasar ese campo a un array para mostrarlo,aqui dejo el codigo actualizado,para que os hagais una mejor idea:

Código:
public class GaleriaFotos extends Activity {

    private Gallery gallery;
    private ImageView imgView;
    private HipotecaDbAdapter dbAdapter;
	private Cursor cursor;
	private long id ;
	
	//String uri = cursor.getString(cursor.getColumnIndex(HipotecaDbAdapter.C_COLUMNA_FOTO1));
	//String uri = "R.drawable.ayto";
	//private int  Idfoto = this.getResources().getIdentifier(uri,null,this.getPackageName());
		
    //private Integer[] Imgid = {Idfoto  };
    
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.galeria);
        
        Intent intent = getIntent();
        Bundle extra = intent.getExtras();
        
        if (extra == null) return;
        
        imgView = (ImageView)findViewById(R.id.ImageView01);	
        
        dbAdapter = new HipotecaDbAdapter(this);
        dbAdapter.abrir();
        
        if (extra.containsKey(HipotecaDbAdapter.C_COLUMNA_ID))
        {
           id = extra.getLong(HipotecaDbAdapter.C_COLUMNA_ID);
           cursor = dbAdapter.getRegistro(id);
    	      }
        
      String uri = cursor.getString(cursor.getColumnIndex(HipotecaDbAdapter.C_COLUMNA_FOTO1));
    	//String uri contiene = "R.drawable.ayto";
    	 int  Idfoto = this.getResources().getIdentifier(uri,null,this.getPackageName());
    	   final Integer[] Imgid = {Idfoto};
    	//final Integer[] Imgid = {Idfoto };
        imgView.setImageResource(Imgid[0]);
        
         gallery = (Gallery) findViewById(R.id.examplegallery);
         gallery.setAdapter(new AddImgAdp(this));

         gallery.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView parent, View v, int position, long id) {
                imgView.setImageResource(Imgid[position]); 
            }
        });
    }
    public class AddImgAdp extends BaseAdapter {
       
		int GalItemBg;
        private Context cont;

        public AddImgAdp(Context c) {
            cont = c;
            TypedArray typArray = obtainStyledAttributes(R.styleable.GalleryTheme);
            GalItemBg = typArray.getResourceId(R.styleable.GalleryTheme_android_galleryItemBackground, 0);
            typArray.recycle();
        }

        public int getCount( ) {
        	
            return Imgid.length;
        }

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

        public long getItemId(int position) {
            return position;
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            ImageView imgView = new ImageView(cont);

            imgView.setImageResource(Imgid[position]);
            imgView.setLayoutParams(new Gallery.LayoutParams(80, 70));
            imgView.setScaleType(ImageView.ScaleType.FIT_XY);
            imgView.setBackgroundResource(GalItemBg);

            return imgView;
        }
    }
    
}
Gracias de antemano!

Última edición por Napster87 Día 14/01/14 a las 12:38:44. Razón: Actualizacion del codigo
Responder Con Cita


  #2  
Viejo 15/01/14, 11:13:15
Array

[xs_avatar]
Napster87 Napster87 no está en línea
Miembro del foro
 
Fecha de registro: may 2013
Mensajes: 74
Tu operador: Movistar

Nuevos avances.....tras leer y leer tutoriales veo que hay que almacenarlo obligatoriamente en un array para irte moviendo por el. Una vez que extraigo los datos del campo y estan en una variable,como pasarla a este array?

He probado a hacer esto:

Integer ims=R.drawable.foto1;
final Integer[] Imgid = {ims};

Y funciona....pero desde un cursor?es imposible?

Alguna otra forma mejor de crear una galeria de imagenes?me estoy planteando hacer un scroll horizontal pero es mas original el imageswitcher.
Saludos!
Responder Con Cita
Respuesta

Estás aquí
Regresar   Portal | Indice > Todo sobre Android > Programación y Desarrollo para Android



Hora actual: 11:25:37 (GMT +1)



User Alert System provided by Advanced User Tagging (Lite) - vBulletin Mods & Addons Copyright © 2026 DragonByte Technologies Ltd.

Contactar por correo / Contact by mail / 邮件联系 /