SearchableActivity.java
...前略... public void query_contacts() { //擷取聯絡人info String[] projection = {ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME}; Cursor cur = managedQuery( ContactsContract.Contacts.CONTENT_URI, //Uri projection, //projection null, //selection query=ContactsContract.Contacts.DISPLAY_NAME null, //selection arguments new String[] {query} //ContactsContract.Contacts.DISPLAY_NAME null ); try { if (cur.moveToFirst()) { int displayNameColumn = cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME); System.out.println("displayNameColumn = "+displayNameColumn); lstImageItem = new ArrayList>(); do { //用HashMap加入圖片與文字訊息 HashMap map = new HashMap (); map.put("ItemImage", R.drawable.icon); map.put("ItemText", String.valueOf(cur.getString(displayNameColumn))); lstImageItem.add(map); }while(cur.moveToNext()); SimpleAdapter saImageItems = new SimpleAdapter(this, lstImageItem, R.layout.night_item,//ImageView*1, TextView*1 new String[] {"ItemImage","ItemText"}, new int[] {R.id.ItemImage,R.id.ItemText} ); listview.setAdapter(saImageItems); } } finally { cur.close(); } } ... //
沒有留言:
張貼留言