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
添加第一個初始列。我如何正確添加列?