Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. EditText searchText;
  2.  
  3. ArrayList<String> phno0 = new ArrayList<String>();
  4. List<String> arrayListNames;
  5. public List<ProfileBean> list;
  6. public SearchableAdapter adapter;
  7. //ProfileBean bean;
  8. String[] cellArray = null;
  9. String contacts;
  10. ListView lv;
  11. String phoneNumber, name;
  12.  
  13. @Override
  14. protected void onCreate(Bundle savedInstanceState) {
  15. super.onCreate(savedInstanceState);
  16.  
  17. ActionBar actionBar = getActionBar();
  18.  
  19.  
  20. lv = (ListView) findViewById(R.id.listview);
  21. list = new ArrayList<ProfileBean>();
  22. getAllCallLogs(this.getContentResolver());
  23. adapter = new SearchableAdapter(getApplication(), list);
  24. lv.setAdapter(adapter);
  25. lv.setItemsCanFocus(false);
  26. lv.setOnItemClickListener(this);
  27. lv.setTextFilterEnabled(true);
  28.  
  29.  
  30. }
  31.  
  32. @Override
  33. protected void onStart() {
  34. // TODO Auto-generated method stub
  35. super.onStart();
  36.  
  37. }
  38.  
  39. public void getAllCallLogs(ContentResolver cr) {
  40.  
  41. Cursor phones = cr.query(
  42. ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null,
  43. null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME
  44. + " ASC");
  45. while (phones.moveToNext()) {
  46. phoneNumber = phones
  47. .getString(phones
  48. .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
  49. name = phones
  50. .getString(phones
  51. .getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
  52.  
  53. list.add(new ProfileBean(name, phoneNumber));
  54.  
  55. }
  56. phones.close();
  57. }
  58.  
  59. int flag = 0
  60. if(list.size() == 0){
  61. list.add(new ProfileBean(name, phoneNumber));
  62. }
  63. for(int i=0;i<list.size();i++){
  64.  
  65. if(!list.get(i).getProfileName().trim().equals(name)){
  66. flag = 1;
  67.  
  68. }else{
  69. flag =0;
  70. break;
  71.  
  72. }
  73. if(flag == 1){
  74. list.add(new ProfileBean(name, phoneNumber));
  75. }
  76.  
  77. if (!myList.contains(newContact))
  78. myList.add(newContact);
  79.  
  80. public ArrayList<String> listWithoutDuplicates(ArrayList<String> duplicateList) {
  81.  
  82. // Converting ArrayList to HashSet to remove duplicates
  83. LinkedHashSet<String> listToSet = new LinkedHashSet<String>(duplicateList);
  84.  
  85. // Creating Arraylist without duplicate values
  86. ArrayList<String> listWithoutDuplicates = new ArrayList<String>(listToSet);
  87.  
  88. return listWithoutDuplicates;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement