Json FUnction 能够解析数据并在 sq-lite 数据库中插入值
for (int i = 0; i < jArray6.length(); i++) {
catagoryid = 5;
json_data = jArray6.getJSONObject(i);
// news_id = Integer.parseInt((json_data.getString("news_id")));
news_id = Double.parseDouble(json_data.getString("news_id"));
news_title = json_data.getString("news_title");
imagepath = json_data.getString("imagepath").trim().getBytes();
news_short_description = json_data
.getString("news_short_description");
news_detail = json_data.getString("news_detail_description");
news_date = json_data.getString("news_date");
website_link = json_data.getString("website_link").trim();
dh = new DBhelper(TaxMann.this);
record_id = dh.AddMsgt1(news_id, catagoryid, news_title,
imagepath, news_short_description, news_date,
news_detail, website_link);
}
这是我的数据库类函数
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("CREATE TABLE " + topstories
+ "(_id INTEGER PRIMARY KEY AUTOINCREMENT," + news_id
+ " double, " + catagory_Id + " integer," + news_title
+ " text," + imagepath + " BLOB, " + short_description
+ " text, " + news_date + " text, " + detailed_news + " text, "
+ website_link + " text)");
db.execSQL("CREATE TABLE " + savednews
+ "(_id INTEGER PRIMARY KEY AUTOINCREMENT," + news_id
+ " double," + news_title + " text," + imagepath + " BLOB, "
+ detailed_news + " text)");
db.execSQL("CREATE TABLE " + date
+ "(_id INTEGER PRIMARY KEY AUTOINCREMENT," + modified_date
+ " integer)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("drop table if exists " + topstories);
db.execSQL("drop table if exists " + savednews);
db.execSQL("drop table if exists " + date);
onCreate(db);
}
// records for newstable
public int AddMsgt1(double newsid, Integer cat_id, String title,
byte[] image, String desc, String date, String detail,
String website) {
db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(news_id, newsid);
cv.put(catagory_Id, cat_id);
cv.put(news_title, title);
cv.put(imagepath, image);
cv.put(short_description, desc);
cv.put(news_date, String.valueOf(date));
cv.put(detailed_news, detail);
cv.put(website_link, website);
long record_id = db.insert(topstories, news_title, cv);
db.close();
return (int) record_id;
}
public Cursor fetchtitle(int catagoryid) {
SQLiteDatabase db1 = this.getReadableDatabase();
cursor = db1.query(topstories,
new String[] { "_id", "news_title", "imagepath",
"short_description", "news_date", "detailed_news", },
"catagory_id=" + catagoryid, null, null, null, null, null);
return cursor;
}
由此我可以显示标题和描述,但我无法显示图像
public void simple_ad(Cursor cursor,int category_id)
{
dh = new DBhelper(this);
ListView list = (ListView)findViewById(R.id.expertscommentsListView);
String[] colummnames = { "news_title","imagepath","descripton"};
cursor = dh.fetchtitle(category_id);
int []id= { R.id.titleTextView,R.id.descriptionTextView,R.id.imagview2};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.new_list, cursor , colummnames,id);
list.setAdapter(adapter);
adapter.notifyDataSetChanged();
list.setOnItemClickListener(this);
}
我已经显示了数据库文件应用从表名中选择 * 我已经显示了数据图像路径列及其值但是我无法显示请帮助我做错了我采取了 r.imageview