In my android project, i have saved camera snapshots along with some description in a SQLite database. Now i want to retrieve all those images plus the description one by one and view them in a xml layout that i have created.
here is my xml layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/showTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Data" />
<ImageView
android:id="@+id/showIv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/marker_default"
/>"
</LinearLayout>
</LinearLayout>
i tried following code snippets seperatly,
String[] columns = new String[]{"_id", "name","description","image"};
Cursor c = myDb.query(DATABASE_TABLE, columns, null, null, null, null, null);
if (c.getCount()>0){
c.moveToNext();
byte[] data = c.getBlob(c.getColumnIndex("image"));
return data;
}else{
return null;
//i converted the byte array to bitmap and displayed on the layout
String result = "";
int iname= c.getColumnIndex("name");
int ides= c.getColumnIndex("description");
TextView tv = (TextView) findViewById(R.id.showTv);
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
result += c.getString(iname) + c.getString(ides);
}
return result;
but i want to get both image and the description together for ALL the data.
please suggest me a method to all the Images and description one by one.
Thank you…
The layout you made won’t support more than one Image. Since there is only one ImageView. Unless you want to do a lot of image manipulation, that is. So you should choose an View that fits your needs. I would look at the Gallery widget or ListView widget. Then you need to create a cursor adapter that will adapt the data from your database to your Gallery or Listview widget.
Take a look at:
listview with sqllite