jeudi 28 janvier 2016

Retrieving an Image(saved in sqlite) from onClickListener

I created a book app, where you can save books from the internet (googleBooksAPI). The BookData (title, author, image) will be saved in an SQLite DB. You can view the books in a listview. If you click on a row ( a book) all the bookdata will be shown in a new activity (bookInfoActivity) My Problem is, that I dont know how to pass the Image of the row i clicked to the bookinfoactivity.

I tried it like following, but as I and you know it will only pass the image of the first row.

`imageView = (ImageView) findViewById(R.id.passed_bookimage);
    bookDBHelper = new BookDBHelper(getApplicationContext());
    sqLiteDatabaseBooks = bookDBHelper.getReadableDatabase();
    cursor2 = bookDBHelper.getInformations(sqLiteDatabaseBooks);
    if (cursor2.moveToPrevious()) {
        {

            byte[] blob= cursor2.getBlob(0);
            Bitmap bookimage = BitmapFactory.decodeByteArray(blob, 0, blob.length);
            imageView.setImageBitmap(bookimage);
            Toast.makeText(this, "here is your image", Toast.LENGTH_SHORT).show();

        }
    }

I think that I have to do something with the cursor.

Do you need more code, infos?

Thanks

Aucun commentaire:

Enregistrer un commentaire