我是 android 新手,在根据 Sqlite 的名称显示来自服务器的图像时遇到问题
IE:
我只在 SQLite 数据库中存储图像名称(文本)(列名称图像),并且我想根据图像想要在 imageview 中显示的 sqlite 图像名称从服务器加载图像
在服务器中,我创建一个像 Cars 这样的文件夹,在该文件夹中我存储带有汽车名称的图像。但在 sqlite 中,我只是添加带有 .jpeg 的文本格式的汽车名称
我的数据库中有两个列名:
当用户选择汽车名称时,在下一个活动中,用户可以看到带有图像的汽车详细信息。
这里我显示详细信息,但我不知道如何显示服务器中的汽车图像
Thanks
这是我的代码:
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.detail_activity);
detailtext= (TextView) findViewById(R.id.detail);
imageView= (ImageView) findViewById(R.id.images);
Intent intent= getIntent();
final String selectedData = intent.getStringExtra("selectedItem");
actionBar.setTitle(selectedData);
dbHelper = new SqlLiteDbHelper(this);
try {
dbHelper.openDataBase();
} catch (SQLException e) {
e.printStackTrace();
}
sqLiteDatabase = dbHelper.getReadableDatabase();
cursor=dbHelper.getdetails(sqLiteDatabase, selectedData);
if (cursor.moveToFirst()) {
detailtext.setText(cursor.getString(0));
String imagename = cursor.getString(1);
String imageUrl = "http://your_server/car/" + imagename ;
Picasso.with(this).load(imageUrl).into(imageView );
}
注意:图像字段是第四列https://i.stack.imgur.com/lqvOQ.png https://i.stack.imgur.com/lqvOQ.png在服务器中,我将图像放入 www.server.com/cars/carnames.jpg
在 sqlite 中,我只需将图像名称粘贴到 .jpg ex:carnames.jpg
SQLite数据库助手
public Cursor getdetails(SQLiteDatabase db,String img)
{
db=this.getReadableDatabase();
Cursor cursor;
cursor=db.query("record",new String[]{DETAIL,IMAGES,ITEMNO + " as _id"},SUBCATEGORY + "='" +img+"'",null,null,null,null);
return cursor;
}