0

I have a SQLite database that contains a table image : this table contains

  • The image id
  • The url of an image

    private static final String CREATE_BD_IMAGE="CREATE TABLE " 
        + TABLE_IMAGE + " (" +
        COL_ID_IMAGE + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
        COL_ADRESS_IMAGE + " TEXT NOT NULL ); " ;
    

I want to know how can I display this image on the button.

Shivam Kumar
  • 1,892
  • 2
  • 21
  • 33
Sally
  • 19
  • 2
  • you can use android query to load images. https://code.google.com/p/android-query/#Image_Loading – Alex248 Jul 10 '13 at 09:40
  • How can i put it on button !! – Sally Jul 10 '13 at 09:56
  • here's a method that i created : public String getImage(int i)//afficher une image { String res; Cursor c = database.rawQuery("SELECT " + COL_ADRESS_IMAGE + "FROM " + TABLE_IMAGE + "WHERE id_image IN (SELECT " + COL_IMAGE_CATEGORY + "FROM " + TABLE_CATEGORY + "WHERE " + COL_ID_CATEGORY + "= '" +i +"')",null ); res=c.toString(); return res; } – Sally Jul 10 '13 at 09:59
  • use ImageButton : aq.id(imageButton).image(url, true, true, 100, R.drawable.default_thumbnail); – Alex248 Jul 10 '13 at 11:14

2 Answers2

0

Hope this will help you

 ImageView view = (ImageView) findViewById(R.id.imageView1);
                        String uriString = c.getString(c
                                        .getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
                        view.setImageURI(Uri.parse(uriString));
Praveen Sharma
  • 4,326
  • 5
  • 25
  • 45
  • I write this into my method or what !! – Sally Jul 10 '13 at 10:16
  • here c is curser `Cursor c = dm.query(query);` so `c.getColumnIndex` must have a uri of that image. – Praveen Sharma Jul 10 '13 at 10:59
  • I haven't an imageview1 in my file .xml and isn't too clear :( – Sally Jul 10 '13 at 21:50
  • Please can you explain me better – Sally Jul 11 '13 at 11:57
  • public String getImage(int id)//afficher une image { database = DBHelper.getReadableDatabase(); Cursor c = database.rawQuery("SELECT " + COL_ADRESS_IMAGE + "FROM "+ TABLE_IMAGE + "WHERE id_image IN (SELECT " + COL_IMAGE_CATEGORY + "FROM " + TABLE_CATEGORY + "WHERE " + COL_ID_CATEGORY + "= '" + id +"')",null ); if(c.moveToFirst()) { String strCatName = c.getString(c.getColumnIndex(COL_ADRESS_IMAGE )); c.close(); database.close(); return strCatName; } else {c.close(); database.close(); return "";} } – Sally Jul 11 '13 at 13:26
  • See here is step by step process for it `1. get image uri from sqlite db` `2. use cursor for query so that the cursor will hold the URI of Image` `3. Use ImageButton and then after set ImageUri to that Button. let me know if need code snippet` – Praveen Sharma Jul 12 '13 at 06:15
  • Thanks a lot for this informations, what i wrote it in the previous commentaire isn't correct !! If it's false tell me what can i do for correct it – Sally Jul 12 '13 at 10:09
  • I just want to know the uri of image is String type?? – Sally Jul 12 '13 at 10:42
  • How can i stored an image in sdcard of mobile ?? – Sally Jul 13 '13 at 11:11
  • sorry for late reply to store images in sd card please check this answer :- http://stackoverflow.com/questions/9396243/how-to-save-the-image-to-sd-card-on-button-click-android – Praveen Sharma Jul 15 '13 at 04:12
0

the Volley library (made by google) has a very intuitive class for an imageView that can have a url , called "NetworkImageView" .

if you load many images urls, you should read more about this library since it could be very handy for you.

you should check it out.

for setting the url, just use setImageUrl .

it has some useful methods for the phases of loading too: setDefaultImageResId , setErrorImageResId.

android developer
  • 114,585
  • 152
  • 739
  • 1,270