成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Android實現多選聯系人

移動開發 Android
有很多網友問多選聯系人實現方式,這里參考了apidemos的例子做了簡單實現。整體思路是使用使用一個ArrayList存放選中的聯系人信息,細節就不說了,貼一下代碼

有很多網友問多選聯系人實現方式,這里參考了apidemos的例子做了簡單實現。

整體思路是使用使用一個ArrayList存放選中的聯系人信息,細節就不說了,貼一下代碼

  1. public class CopyContactsListMultiple extends ListActivity implements OnClickListener{  
  2.    
  3. private final int UPDATE_LIST=1;  
  4. ArrayList contactsList; //得到的所有聯系人  
  5. ArrayList getcontactsList; //選擇得到聯系人  
  6. private Button okbtn;  
  7. private Button cancelbtn;  
  8. private ProgressDialog proDialog;  
  9.    
  10. Thread getcontacts;  
  11. Handler updateListHandler = new Handler() {  
  12. public void handleMessage(Message msg) {  
  13. switch (msg.what) {  
  14.    
  15. case UPDATE_LIST:  
  16. if (proDialog != null) {  
  17. proDialog.dismiss();  
  18. }  
  19. updateList();  
  20. }  
  21. }  
  22. };  
  23. public void onCreate(Bundle savedInstanceState) {  
  24. super.onCreate(savedInstanceState);  
  25. setContentView(R.layout.contactslist);  
  26. contactsList=new ArrayList();  
  27. getcontactsList=new ArrayList();  
  28.    
  29. final ListView listView = getListView();  
  30. listView.setItemsCanFocus(false);  
  31. listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);  
  32. okbtn=(Button)findViewById(R.id.contacts_done_button);  
  33. cancelbtn=(Button)findViewById(R.id.contact_back_button);  
  34. okbtn.setOnClickListener(this);  
  35. cancelbtn.setOnClickListener(this);  
  36.    
  37. getcontacts=new Thread(new GetContacts());  
  38. getcontacts.start();  
  39. proDialog = ProgressDialog.show(CopyContactsListMultiple.this, “loading”,“loading”, truetrue);  
  40.    
  41. }  
  42.    
  43. @Override 
  44. protected void onResume() {  
  45. // TODO Auto-generated method stub  
  46. super.onResume();  
  47.    
  48. }  
  49.    
  50. void updateList(){  
  51. if(contactsList!=null)  
  52. setListAdapter(new ArrayAdapter(this,  
  53. android.R.layout.simple_list_item_multiple_choice, contactsList));  
  54.    
  55. }  
  56.    
  57. @Override 
  58. protected void onListItemClick(ListView l, View v, int position, long id) {  
  59. // TODO Auto-generated method stub  
  60. if(!((CheckedTextView)v).isChecked()){  
  61.    
  62. CharSequence num=((CheckedTextView)v).getText();  
  63. getcontactsList.add(num.toString());  
  64. }  
  65. if(((CheckedTextView)v).isChecked()){  
  66. CharSequence num=((CheckedTextView)v).getText();  
  67. if((num.toString()).indexOf(“[")>0){  
  68. String phoneNum=num.toString().substring(0, (num.toString()).indexOf("\n"));  
  69. getcontactsList.remove(phoneNum);  
  70. Log.d("remove_num"""+phoneNum);  
  71. }else{  
  72. getcontactsList.remove(num.toString());  
  73. Log.d("remove_num"""+num.toString());  
  74. }  
  75. }  
  76. super.onListItemClick(l, v, position, id);  
  77. }  
  78. class GetContacts implements Runnable{  
  79. @Override 
  80. public void run() {  
  81. // TODO Auto-generated method stub  
  82. Uri uri = ContactsContract.Contacts.CONTENT_URI;  
  83. String[] projection = new String[] {  
  84. ContactsContract.Contacts._ID,  
  85. ContactsContract.Contacts.DISPLAY_NAME,  
  86. ContactsContract.Contacts.PHOTO_ID  
  87. };  
  88. String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + “ = ’1′”;  
  89. String[] selectionArgs = null;  
  90. String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + “ COLLATE LOCALIZED ASC”;  
  91. Cursor cursor=managedQuery(uri, projection, selection, selectionArgs, sortOrder);  
  92. Cursor phonecur = null;  
  93.    
  94. while (cursor.moveToNext()){  
  95.    
  96. // 取得聯系人名字  
  97. int nameFieldColumnIndex = cursor.getColumnIndex(android.provider.ContactsContract.PhoneLookup.DISPLAY_NAME);  
  98. String name = cursor.getString(nameFieldColumnIndex);  
  99. // 取得聯系人ID 

 

  1. String contactId = cursor.getString(cursor.getColumnIndex(android.provider.ContactsContract.Contacts._ID));  
  2. phonecur = managedQuery(android.provider.ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, android.provider.ContactsContract.CommonDataKinds.Phone.CONTACT_ID + “ = ” + contactId, null, null);  
  3. // 取得電話號碼(可能存在多個號碼)  
  4. while (phonecur.moveToNext()){  
  5. String strPhoneNumber = phonecur.getString(phonecur.getColumnIndex(android.provider.ContactsContract.CommonDataKinds.Phone.NUMBER));  
  6. if(strPhoneNumber.length()>4)  
  7. contactsList.add(“18610011001″+“\n測試”);  
  8. //contactsList.add(strPhoneNumber+”\n”+name+”");  
  9.    
  10. }  
  11. }  
  12. if(phonecur!=null)  
  13. phonecur.close();  
  14. cursor.close();  
  15.    
  16. Message msg1=new Message();  
  17. msg1.what=UPDATE_LIST;  
  18. updateListHandler.sendMessage(msg1);  
  19. }  
  20. }  
  21. @Override  
  22. protected void onPause() {  
  23. // TODO Auto-generated method stub  
  24. super.onPause();  
  25.    
  26. }  
  27.    
  28. @Override  
  29. protected void onDestroy() {  
  30. contactsList.clear();  
  31. getcontactsList.clear();  
  32. super.onDestroy();  
  33. }  
  34.    
  35. @Override  
  36. public void onClick(View v) {  
  37. // TODO Auto-generated method stub  
  38. switch (v.getId()) {  
  39. case R.id.contacts_done_button:  
  40. Intent i = new Intent();  
  41. if(getcontactsList!=null>>getcontactsList.size()>0){  
  42. Bundle b = new Bundle();  
  43. b.putStringArrayList(“GET_CONTACT”, getcontactsList);  
  44. i.putExtras(b);  
  45. }  
  46. setResult(RESULT_OK, i);  
  47. CopyContactsListMultiple.this.finish();  
  48. break;  
  49. case R.id.contact_back_button:  
  50. CopyContactsListMultiple.this.finish();  
  51. break;  
  52. default:  
  53. break;  
  54. }  
  55. }  
  56. @Override  
  57. public boolean onKeyDown(int keyCode, KeyEvent event) {  
  58. // TODO Auto-generated method stub  
  59. if(keyCode==KeyEvent.KEYCODE_BACK){  
  60. Intent i = new Intent();  
  61. Bundle b = new Bundle();  
  62. b.putStringArrayList(“GET_CONTACT”, getcontactsList);  
  63. i.putExtras(b); // }  
  64. setResult(RESULT_OK, i);  
  65. }  
  66. return super.onKeyDown(keyCode, event);  
  67. }  

xml:

  1. <?xml version=“1.0″ encoding=“utf-8″?> 
  2. <LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”  
  3.         android:orientation=“vertical” android:layout_width=“fill_parent”  
  4.         android:layout_height=“fill_parent”> 
  5.    
  6.    
  7.         <ListView android:id=“@+id/android:list”   
  8.                 android:layout_height=“fill_parent”   
  9.                 android:layout_width=“fill_parent”  
  10.                  android:layout_marginLeft=“10dip”  
  11.                 android:layout_marginRight=“10dip”   
  12.                 android:layout_marginTop=“10dip”  
  13.                 android:layout_weight=“1.0″> 
  14.         </ListView> 
  15.    
  16.         <LinearLayout android:layout_width=“fill_parent”  
  17.                 android:layout_height=“wrap_content”  
  18.                 android:layout_weight=“0″ android:orientation=“horizontal”  
  19.                 android:gravity=“center” android:layout_marginLeft=“10dip”  
  20.                 android:layout_marginRight=“10dip” android:layout_marginBottom=“10dip”  
  21.                 android:weightSum=“1″> 
  22.    
  23.                 <Button android:id=“@+id/contacts_done_button”  
  24.                         android:textSize=“17dip”  
  25.                         android:layout_marginRight=“10dip” android:layout_width=“0dip”  
  26.                         android:layout_height=“wrap_content” android:layout_weight=“0.35″  
  27.                         android:text=“sure” /> 
  28.    
  29.                 <Button android:id=“@+id/contact_back_button”  
  30.                         android:layout_marginLeft=“10dip” android:textSize=“17dip”  
  31.                         android:layout_width=“0dip” android:layout_height=“wrap_content”  
  32.                         android:layout_weight=“0.35″ android:text=“back” /> 
  33.         </LinearLayout> 
  34.    
  35. </LinearLayout> 

效果如圖:

 

device-2012-02-06-091606.png

【編輯推薦】

  1. Android編程方法大PK:NDK vs. RenderScript 
  2. Android SQLite3命令詳解教程 
  3. 如何開發基于Adobe AIR的Android應用 
責任編輯:冰凝兒 來源: DEVDIV博客
相關推薦

2014-12-30 11:51:35

ListViewItem View

2011-05-26 14:42:34

Android 手機

2010-01-27 14:08:56

Android查詢聯系

2015-01-21 15:50:55

Android源碼全國城市列表

2015-11-11 10:17:15

ios9聯系人框架干貨

2020-02-02 14:45:55

聯系人開源工具

2011-08-12 10:16:10

iPhone通訊錄聯系人

2012-03-26 21:38:36

智能

2013-09-17 09:51:49

谷歌Bump移動應用

2019-11-07 09:20:36

Windows 10聯系人Outlook

2011-09-21 14:33:17

點心

2012-02-24 09:25:58

2013-05-07 09:26:26

Office 365微軟

2015-09-24 11:37:43

2011-10-14 09:42:06

點心通訊錄

2012-02-02 17:16:11

Windows PhoC#聯系人資料

2020-04-29 09:55:13

蘋果谷歌API

2010-11-23 11:21:25

Microsoft L

2014-12-10 10:45:56

Android應用權限

2022-01-04 15:34:31

鴻蒙HarmonyOS應用
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 欧美激情在线精品一区二区三区 | 久久99网 | 久久精品免费一区二区 | 婷婷午夜天| 欧美日韩福利 | 玖玖免费| 欧洲毛片 | 99久热在线精品视频观看 | 久久久久国产一区二区三区四区 | 国产精品五区 | 天天色av| 欧美日韩久久精品 | 亚洲 欧美 激情 另类 校园 | 日韩成人在线网址 | 国产一极毛片 | 欧美成人一区二区 | 黄色av一区| jlzzjlzz国产精品久久 | 日本黄色影片在线观看 | 在线婷婷| 日韩一区二区在线观看 | 网站黄色av| 欧美一级毛片免费观看 | 国产精品一区二区不卡 | 久久久99精品免费观看 | 久久久精品一区二区三区 | 91极品尤物在线播放国产 | 亚洲视频免费在线观看 | 能看的av网站 | 国产欧美一区二区三区国产幕精品 | 日韩在线视频精品 | 成人影音 | 成人午夜免费在线视频 | 国产精品一区二区三区在线 | 午夜爽爽爽男女免费观看 | 99热精品在线 | 夜夜夜久久久 | 美女久久久久久久 | 久久久爽爽爽美女图片 | 久久久久国产精品 | 超碰人人人人 |