安卓,sqlite数据库如何导入listview?

如题... 如题 展开
 我来答
幻亦痕
2014-04-24
知道答主
回答量:13
采纳率:0%
帮助的人:6.1万
展开全部
listItemAdapter = new SimpleAdapter(MenuList.this, listData,// 数据源
R.layout.menulistitem,// ListItem的XML实现
// 动态数组与ImageItem对应的子项
new String[] { "mNo", "mName", "mIslove", "mPrice", "mImage" },
// ImageItem的XML文件里面的一个ImageView,两个TextView ID
new int[] { R.id.tvNo, R.id.tvMenuname, R.id.iBIslove,
R.id.tvPrice, R.id.ibMenuImage });

public void getAllData() {

mDb = openOrCreateDatabase("system.db",
SQLiteDatabase.OPEN_READWRITE, null);
Cursor cursor = mDb.rawQuery(
"select mNo,mName,mIslove,mPrice,mImage from " + tableName
+ " where mClass= " + "'" + tbClass + "'", null);
TextView tvClassname = (TextView) findViewById(R.id.tvClassname);
tvClassname.setText(tbClass);
num = cursor.getCount();
if (num > 0) {
mListNo = new String[num];
mListName = new String[num];

mListPrice = new double[num];
mListLove = new Bitmap[num];
int noindex = 0;
int nameindex = 0;
int priceindex = 0;
int loveindex = 0;
String eNo = "";
String eName = "";
double ePrice = 0;
int eIslove = 0;
Bitmap eIslo = null;
byte[] imgArr = null;
Bitmap photo = null;
// 必须使用moveToFirst方法将记录指针移动到第1条记录的位置
cursor.moveToFirst();
do {
eNo = cursor.getString(cursor.getColumnIndex("mNo"));
mListNo[noindex++] = eNo;
eName = cursor.getString(cursor.getColumnIndex("mName"));
mListName[nameindex++] = eName;
eIslove = cursor.getInt(cursor.getColumnIndex("mIslove"));
if (eIslove == 0) {
eIslo = BitmapFactory.decodeResource(this.getResources(),
R.drawable.islove01);
} else {
eIslo = BitmapFactory.decodeResource(this.getResources(),
R.drawable.islove02);
mListLove[loveindex++] = eIslo;
}
ePrice = cursor.getDouble(cursor.getColumnIndex("mPrice"));
mListPrice[priceindex++] = ePrice;
imgArr = cursor.getBlob(cursor.getColumnIndex("mImage"));
HashMap<String, Object> item = new HashMap<String, Object>();
item.put("mNo", eNo);
item.put("mName", eName);
item.put("mIslove", eIslo);
item.put("mPrice", ePrice);
photo = BitmapFactory.decodeByteArray(imgArr, 0, imgArr.length);
item.put("mImage", photo);
listData.add(item);
} while (cursor.moveToNext());

}
mDb.close();
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式