RaagaSudha RaagaSudha - 1 year ago 50
Android Question

How to store images in sqlite database and display them?

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.

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


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.


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;


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;
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;


Answer Source

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.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download