我是Android开发的新手,我正试图在ImageSwitcher中显示我的sqlite数据库中的图像列表。我只保存了像这样的@ drawables / photo1。
我可以从Cursor
创建一个字段数组吗?
这是我的代码:
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;
}
}
}