如何存储在SQLite数据库的图像,并显示它们? [英] How to store images in sqlite database and display them?

查看:243
本文介绍了如何存储在SQLite数据库的图像,并显示它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序需要随着Android的图像显示的问题。我已存储在sqlite的数据库,并显示它们的问题。我创建的资产文件夹中的文件夹DBimages。现在,所有我的图片里有DBimages文件夹中。

In my application I need to display questions along with images in Android. I have stored questions in sqlite db and displaying them. I have created a folder DBimages in assets folder. Now all my images are there in DBimages folder.

我已经创建了两个班。我能够显示来自本地SQLite数据库的问题和选择,但我无法显示存储在资产影像\ DBimages \ abc.png

I have created two classes. I am able to display the question and options from local sqlite db but I am unable to display the image which is stored in assets\DBimages\abc.png.

所有图像的名称都存储在照片列的SQLite数据库表。但如何显示与该特定问题的图像。请帮我对此。

The names of all the images are stored in pictures column in sqlite db table. But how to display the image related to that particular question. Please help me regarding this.

UserBO.java

public String getQuestion() {
return question;
}
public void setQuestion(String question) {
this.question = question;
}
public String getImage() {
return pictures;
}

public void setImage(String pictures) {
this.pictures = pictures;
}

Select.java

ArrayList<UserBO> usersList = new ArrayList<UserBO>();
for (int i = 0; i < stringList.size(); i++) {
ArrayList<String> list = stringList.get(i);
UserBO user = new UserBO();
try {
user.id = Integer.parseInt(list.get(0));
user.name = list.get(2);
user.question = list.get(3);
user.option1 = list.get(4);
user.option2 = list.get(5);
user.option3 = list.get(6);
user.option4 = list.get(7);
user.option5 = list.get(8);
user.pictures = list.get(9);
user.answer = (list.get(10));
} 
catch (Exception e){}
public View getView(int position, View convertView, ViewGroup parent){
View view = convertView;
try{
if (view == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.list_item, null); 
}
final UserBO listItem = mList.get(position);                
if (listItem != null) {
( (TextView) view.findViewById(R.id.tv_question) ).setText( listItem.getQuestion()+"");
((ImageView) view.findViewById(R.id.imageView1)).setImageResource(R.drawable.f);
( (RadioButton) view.findViewById(R.id.option1) ).setText( listItem.getOption1() );
( (RadioButton) view.findViewById(R.id.option2) ).setText( listItem.getOption2()+"" );
( (RadioButton) view.findViewById(R.id.option3) ).setText( listItem.getOption3()+"" );
( (RadioButton) view.findViewById(R.id.option4) ).setText( listItem.getOption4()+"" );
( (RadioButton) view.findViewById(R.id.option5) ).setText( listItem.getOption5()+"" );
}}catch(Exception e){}
return view;

} }

推荐答案

有些丑陋的方式,存储在SQLite数据库图像。 只是存储在SD卡的图像和保存在SQLite数据库这些图像的相关路径。

Some ugly way, to store images in SQLite database. Just store images in sdcard and save the relevant path of those images in SQLite database.

In your need, put the images in either drawable folder or in asset folder then store its
name(with question ID or number also) in SQLite and use it in application.

这篇关于如何存储在SQLite数据库的图像,并显示它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆