2015-06-22 113 views
0

我有一個ListView所有用戶的聯繫人,並且我想在每個聯繫人名稱前面添加一個帶有第一個首字母的圓圈,就像在Google通訊錄應用中一樣。我不知道如何添加一個新的列到ListView將列添加到ListView中

這是我在我的活動創建列表:

private CursorAdapter mAdapter; 
    private String currentQuery; 
    private static final String[] PROJECTION = { 
      Contacts._ID, 
      Contacts.DISPLAY_NAME_PRIMARY, 
      Contacts.HAS_PHONE_NUMBER 
    }; 
    private static final String[] FROM = { Contacts.DISPLAY_NAME_PRIMARY.substring(0,1), Contacts.DISPLAY_NAME_PRIMARY }; 
    private static final int[] TO = { R.id.first_initial, R.id.contact_text }; 
    private static final String SELECTION = "(" + Contacts.IN_VISIBLE_GROUP + 
     " = 1) AND (" + Contacts.HAS_PHONE_NUMBER + " != 0)"; 


    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     mAdapter = new SimpleCursorAdapter(getActivity(), R.layout.contacts_list_item, null, FROM, TO, 0); 
    } 

它能正常工作,然後我試圖通過添加Contacts.DISPLAY_NAME_PRIMARY.substring(0,1),FROM並添加R.id.first_initial,TO添加第一個初始列。我如何正確添加列?

回答

0

您必須在適配器的getView處返回一個包含該組件的View。