将图像添加到 ListView 项目和详细信息
大家好,我一直在关注本教程: http://coenraets.org/blog/android-示例/androidtutorial/ 。我从中得到了我需要的东西,但现在我遇到了一个问题。 基本上,我需要的是能够为每个员工添加一张照片。我想要在创建的列表上显示缩略图,并在详细信息页面上显示全尺寸照片。 我该怎么做?
我尝试在数据库中添加照片标记,
String sql = "CREATE TABLE IF NOT EXISTS employee (" +
"_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
"firstName TEXT, " +
"lastName TEXT, " +
"title TEXT, " +
"officePhone TEXT, " +
"cellPhone TEXT, " +
"email TEXT, " +
photo IMAGE," + "managerId INTEGER)";
db.execSQL(sql);
然后添加 values.put("photo", "@drawable/icon");
。
然后在EmployeeDetails
中我添加了这一行:
photo = (ImageView) findViewById(R.id.image);
photo.setTag(cursor.getString(cursor.getColumnIndex("photo")));
当然我导入了ImageView
和protected ImageView photo;
对于详细信息布局,我添加了:
<ImageView
android:id="id/image
android:layout_width="wrap_content"
android:layout_heigh=wrap_content
询问我是否没有设法让自己足够清楚。 我试图为员工的详细信息部分放一张照片,但我并没有尝试制作缩略图,但事实是,我完成了整个过程,结果没有错误,但当我运行它时,应用程序崩溃了。
Hello everyone i've been following this tutorial: http://coenraets.org/blog/android-samples/androidtutorial/ . I got what i needed from it , but now i have reached a problem.
Basically , what i need is to be able to add a picture for each employee. I want a thumbnail picture on the list created and a full sized photo on the details page.
How can i do this?
I tried to add a Photo marker in the database
String sql = "CREATE TABLE IF NOT EXISTS employee (" +
"_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
"firstName TEXT, " +
"lastName TEXT, " +
"title TEXT, " +
"officePhone TEXT, " +
"cellPhone TEXT, " +
"email TEXT, " +
photo IMAGE," + "managerId INTEGER)";
db.execSQL(sql);
then i added values.put("photo", "@drawable/icon");
.
Then in EmployeeDetails
i added this line :
photo = (ImageView) findViewById(R.id.image);
photo.setTag(cursor.getString(cursor.getColumnIndex("photo")));
Of course i imported ImageView
and protected ImageView photo;
and for the Details layout i added:
<ImageView
android:id="id/image
android:layout_width="wrap_content"
android:layout_heigh=wrap_content
Ask if i didn't managed to make myself clear enough.
I was trying to put a photo for the details section of the employee I wasn't trying to make a thumbnail image yet the thing is , i did the whole thing and it came out without errors but when i run it , the app crashes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 blob 从数据库存储和检索图像,this 会给出一个更好的主意:
您还将资产文件夹路径作为文本存储在数据库中,并使用它从 sql 检索路径:
然后你的sql:
然后你可以通过以下方式从资产文件夹中获取drawable:
using blob storing and retriving image from database, this would give a better idea:
you also store assets folder path in db as text and use it to retrieve path from sql:
then your sql:
then you can get drawable from assets folder by: