![]() |
|
| 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 |
«
Tema Anterior
|
Siguiente tema
»
|
|
Herramientas |
|
#1
|
||||
|
||||
|
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;
}
}
}
Última edición por Napster87 Día 14/01/14 a las 12:38:44 Razón: Actualizacion del codigo |
|
|
|
#2
|
||||
|
||||
|
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! |
| Respuesta |
Estás aquí
|
||||||
|
||||||
«
Tema Anterior
|
Siguiente tema
»
| Herramientas | |
|
|
Hora actual: 12:14:24 (GMT +1)
HTCMania: líderes desde el 2007





