Android GridView with database

I've got problem with my grid view. I would like to store images in table and then display them in grid view.

 // ImageAdapter

    String[] strings = db.getPictures();
    Integer[] ints = new Integer[strings.length];
    for (int i=0; i < strings.length; i++) {
        ints[i] = Integer.parseInt(strings[i]);
    }
    imageView.setImageResource(ints[position]);
    return imageView;


   //DatabaseHandler

 public String[] getPictures(){
    int i=0;

    String selectQuery = "SELECT pictureName FROM Category";
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor c = db.rawQuery(selectQuery, null);
    int rowsNumber=c.getCount();
    String[] mThumbIds;
    mThumbIds= new String[rowsNumber];

    if (c.moveToFirst()) {
        do {
            mThumbIds[i]=c.getString(0);
            i++;
        } while (c.moveToNext());
    }

    return mThumbIds;
}

And when i run my app it crush at starting. Single string I save like R.drawable.ic_work

Answers


As you said you are saving R.drawable.ic_work as string.

The problem is you are using imageView.setImageResource(ints[position]); while R.drawable.ic_work is String.

Solution is instead of storing R.drawable.ic_work as String store it as int because your R.drawable.ic_work represents with an int ID.


In most scenarios, your device wont be able to load a single original image into memory leave alone a list. You need to scale your image before you display it.


Need Your Help

BizTalk 2013 Start Message Processing Before Source File Finishes?

sql-server biztalk esb biztalk-2013

We've got a large &amp; complicated file that takes a long time to disassemble (say, an hour). It would be great if we could spin off messages as they leave the receive pipeline and start on their

So what's the deal with ARC and releasing properties/subviews on viewDidUnload

ios automatic-ref-counting xcode4.3 objective-c-2.0

I'm still learning iOS development and have been working with various tutorials and books. Some pre-ARC, some with ARC.