2011-04-06 72 views
0

緩存由於使用了Cursor,我使用了ContentQueryMap。如何從ContentQueryMap獲取SortedMap?

事實是,我認爲對於每個ContentQueryMap,我只能得到查詢的單個列......但我不確定這一點。

假設遊標返回2列:key,value。

我想這樣做一個SortedMap:,,...

問:怎麼想出來的SortedMap從遊標泰德開始選擇兩列,從ContentQueryMap傳遞(因爲查詢必須緩存)?

回答

0
  ContentQueryMap mQueryMap = new ContentQueryMap(cursor, BaseColumns._ID, true, null); 

      Comparator<Long> numberAmaxB = new Comparator<Long>() { 
       @Override public int compare(Long s1, Long s2) { 
        if (s1<s2) 
         return 1; 
        else if (s1>s2) 
         return -1; 
        else 
         return 0; 
       }   
      }; 
      SortedMap<Long, String> mySortedMap = new TreeMap<Long, String>(numberAmaxB); 

      for (Map.Entry<String, ContentValues> row : mQueryMap.getRows().entrySet()) { 

       Long _ID = Long.valueOf(row.getKey()); 
       String data= row.getValue().getAsString("data_column"); 
      conversationsSortedMap.put(_ID, data); 
      } 

完成:conversationsSortedMap是SortedMap!