Help with SimpleCursorTreeAdapter and getChildrenCursor ()

I have a sqlite database with three columns: id, date and row. For one date, several lines can be connected, so I have several lines with the same date with only different lines.

I want to use ExpandableListView to display this data. I need to implement getChildrenCursor () in SimpleCursorTreeAdapter to use it for this purpose, but I'm not sure how to do it. I looked through this one and I see that it uses managedQuery, but I don’t have a content provider, so I can’t use it. From what I understood , the goal of getChildrenCursor () is to get the cursor only with data that can be placed in the child, but I can not see how this method can separate records according to their dates, since it only passed the Cursor as parameter.

+3
source share
3 answers
public class MyExpandableListAdapter extends SimpleCursorTreeAdapter {

    public MyExpandableListAdapter(Cursor cursor, Context context, int groupLayout,
            int childLayout, String[] groupFrom, int[] groupTo, String[] childrenFrom,
            int[] childrenTo) {
        super(context, cursor, groupLayout, groupFrom, groupTo, childLayout, childrenFrom,
                childrenTo);
    }

    @Override
    @SuppressWarnings("deprecation")
    protected Cursor getChildrenCursor(Cursor groupCursor) {
        // Given the group, we return a cursor for all the children within that group 
        // Return a cursor that points to this contact phone numbers
        Uri.Builder builder = People.CONTENT_URI.buildUpon();
        ContentUris.appendId(builder, groupCursor.getLong(mGroupIdColumnIndex));
        builder.appendEncodedPath(People.Phones.CONTENT_DIRECTORY);
        Uri phoneNumbersUri = builder.build();
        // The returned Cursor MUST be managed by us, so we use Activity helper
        // functionality to manage it for us.
        return managedQuery(phoneNumbersUri, mPhoneNumberProjection, null, null, null);
    }
}
0
source

I know this after 8 months, but still.

. SQLite db.query(...) - . - .

0

ContentProvider, AsyncTask. changeCursor onPostExecute .

managedQuery , API 11.

The groupCursor object can be used to say "_id" to use when querying for its child data. e.g. SELECT * FROM 'TABLE' WHERE ID = ?. "?" which is the identifier column from the group cursor, which is most likely to be used as a foreign key in another table. If you're still confused, try searching for “Database Normalization” on Google.

0
source

Source: https://habr.com/ru/post/1796446/


All Articles