ListView using two cursoradapters?

前端 未结 4 668
陌清茗
陌清茗 2020-12-08 21:54

I have some code which executes two queries against a database and returns two cursor objects. Is there any way that I can combine these two cursors so that all the L

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-08 22:39

    FYI - An example of using MergeCursor()

    c = Cursor containing Contacts columns from Contacts.CONTENT_URI

    private Cursor mergeCursorSubset(Cursor c) {
    
        int userMobile = ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE,
            workMobile = ContactsContract.CommonDataKinds.Phone.TYPE_WORK_MOBILE;
    
        String storedNumber = ContactsContract.CommonDataKinds.Phone.NUMBER,
                displayName =ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
                numberType = ContactsContract.CommonDataKinds.Phone.TYPE,
                contactKey = ContactsContract.CommonDataKinds.Phone.LOOKUP_KEY,
                whereClausePre = contactKey+" = '",
                whereClausePost = "AND ("+numberType+" = '"+userMobile+"' OR "+numberType+" = '"+workMobile+"'";
    
    
        Uri lookupUri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;;
    
        Cursor [] m = new Cursor[c.getCount()]; 
    
        if (c.moveToFirst())
            for (int k = 0; k

提交回复
热议问题