我将图像和文本保存在数据库中,为此我将图像转换为字符串,反之亦然。 现在我想在列表视图中显示这两个。 我对textview没有任何问题,它在每个列表中都有所不同,但在imageview中,图像总是相同的,我从图库中选择。 我正在分享我的代码。 请帮忙 提前谢谢
@Override
public int getCount() {
// TODO Auto-generated method stub
return arr_getset.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
class ViewHolder {
TextView imgname;
ImageView img;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v=convertView;
if(convertView==null){
/****** Inflate tabitem.xml file for each row ( Defined below ) *******/
v = inflater.inflate(R.layout.list_view, parent, false);
/****** View Holder Object to contain tabitem.xml file elements ******/
vh = new ViewHolder();
vh.imgname = (TextView) v.findViewById(R.id.text1);
vh.img = (ImageView) v.findViewById(R.id.img1);
/************ Set holder with LayoutInflater ************/
v.setTag( vh );
}
else
vh=(ViewHolder)v.getTag();
vh.imgname.setText(arr_getset.get(position).getImagename());
vh.img.setImageBitmap(
BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length));
return v;
}
public void ReadValue() {
idb.open();
Cursor mcursor = idb.imageDetailCursor();
while (mcursor.moveToNext()) {
beanClass = new Bean_Class();
beanClass.setId(mcursor.getInt(0));
String imgg = beanClass.setImage(mcursor.getString(1));
imageAsBytes = Base64.decode(imgg.getBytes(), Base64.DEFAULT);
beanClass.setImagename(mcursor.getString(2));
arr_getset.add(beanClass);
}
Log.d("CHECK11", arr_getset.size() + "@@@");
if (mcursor.isAfterLast()) {
mcursor.close();
}
mcursor.close();
idb.close();
}
}
答案 0 :(得分:1)
thanx很多nitzanj你就在这里是解决方案。
if(convertView==null){
/****** Inflate tabitem.xml file for each row ( Defined below ) *******/
v = inflater.inflate(R.layout.list_view, parent, false);
/****** View Holder Object to contain tabitem.xml file elements ******/
vh = new ViewHolder();
vh.imgname = (TextView) v.findViewById(R.id.text1);
vh.img = (ImageView) v.findViewById(R.id.img1);
/************ Set holder with LayoutInflater ************/
v.setTag( vh );
}
else
vh=(ViewHolder)v.getTag();
vh.img.setImageBitmap(image.get(position));
vh.imgname.setText(arr_getset.get(position).getImagename());
return v;
}
public List<Bitmap> ReadValue() {
image = new ArrayList<Bitmap>();
idb.open();
Cursor mcursor = idb.imageDetailCursor();
while (mcursor.moveToNext()) {
beanClass = new Bean_Class();
beanClass.setId(mcursor.getInt(0));
String imgg = beanClass.setImage(mcursor.getString(1));
imageAsBytes = Base64.decode(imgg.getBytes(), Base64.DEFAULT);
Bitmap im=BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length);
image.add(im);
beanClass.setImagename(mcursor.getString(2));
arr_getset.add(beanClass);
}
Log.d("CHECK11", arr_getset.size() + "@@@");
if (mcursor.isAfterLast()) {
mcursor.close();
}
mcursor.close();
idb.close();
return image;
}