As my application is set up, I have a ListView supported by CursorLoader, messages made by users. Each post has user comments that are associated with it. Each listitem has its own text view at the bottom, where comments are scrolled (with right or left swipe). Inside each of the custom text views, there is a list of comments related to its specific post. Its kind of comments about the Google+ app, with the exception of the elements, scroll. Comments are stored in a separate database table than messages.
The problem I am facing is that every time BindView is called, I query the database and retrieve the cursor with the corresponding comments and add it to the user text view list. It seems really inefficient to query the comment database table for each item. So I'm wondering if there would be an ideal way to handle this. My code looks something like this:
public void bindView(View view, Context context, Cursor cursor) final String rowid = cursor.getString(cursor.getColumnIndexOrThrow(Database.ROWID)); Cursor commentcursor = c.getContentResolver().query(DatabaseProvider.CONTENT_URI_COMMENTTABLE, freeWriteCommentColumns, Database.PARENTPOSTROWID + " =?", new String[]{rowid}, null); commentcursor.moveToFirst(); while (commentcursor.isAfterLast() == false){
I looked at CursorJoiners, but that doesn't seem to be useful. I played with JOINS, but this makes the number of lines much larger than necessary. I am now playing with the holder for the comment table cursor, which is created when the adapter is created and set as a global variable. It seems like a decent prospect because I donβt need to demand every time. I'm just not sure how to deal with this situation.
android sqlite android-listview android-cursoradapter android-cursorloader
Papajohn000
source share