hi,
to display the contact i have used this coding
to display the contact i have used this coding
Code:
[LEFT][SIZE=2]Cursor cursor = getContacts();[/SIZE]
[SIZE=2]String[] fields = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] String[] { ContactsContract.Data.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]DISPLAY_NAME[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2] };[/SIZE]
[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//this.setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_checked,));[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]
[SIZE=2]SimpleCursorAdapter adapter = [/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] SimpleCursorAdapter([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2],[/SIZE]
[SIZE=2]android.R.layout.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]simple_list_item_checked[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2], cursor, fields,[/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][] { R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]contactEntryText[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2] });[/SIZE][/LEFT]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mContactList[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setAdapter(adapter);[/SIZE][/LEFT]
exception is thrown, i got successful in textview but i want it in listview(scrollable)
to add the contact, i have used the code
Code:
[SIZE=2][LEFT]ArrayList<ContentProviderOperation> ops = [/LEFT]
[/SIZE][LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ArrayList<ContentProviderOperation>();[/SIZE]
[LEFT][SIZE=2]ops.add(ContentProviderOperation.[I]newInsert[/I](Data.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]CONTENT_URI[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2])[/SIZE]
[SIZE=2].withValue(Data.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]RAW_CONTACT_ID[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2],0)[/SIZE]
[SIZE=2].withValue(Data.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]MIMETYPE[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2], Phone.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]CONTENT_ITEM_TYPE[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2])[/SIZE]
[SIZE=2].withValue(Phone.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]NUMBER[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"1-800-GOOG-411"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2].withValue(Phone.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]TYPE[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2], Phone.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]TYPE_CUSTOM[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2])[/SIZE]
[SIZE=2].withValue(Phone.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LABEL[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"free directory assistance"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE][/LEFT]
[SIZE=2].build());[/SIZE]
[SIZE=2][COLOR=#7f0055][FONT=Courier New][B]try[/B][/FONT][/COLOR][COLOR=black][FONT=Courier New] {[/FONT][/COLOR][/SIZE]
[SIZE=2][COLOR=black][FONT=Courier New] getContentResolver().applyBatch(ContactsContract.[/FONT][/COLOR][I][COLOR=#0000c0][FONT=Courier New]AUTHORITY[/FONT][/COLOR][/I][COLOR=black][FONT=Courier New], ops);[/FONT][/COLOR][/SIZE]
[SIZE=2][COLOR=black][FONT=Courier New] toast = Toast.[I]makeText[/I](ctx,[/FONT][/COLOR][COLOR=#2a00ff][FONT=Courier New]"Deleted"[/FONT][/COLOR][COLOR=black][FONT=Courier New], duration);[/FONT][/COLOR][/SIZE]
[SIZE=2][COLOR=black][FONT=Courier New] toast.show();[/FONT][/COLOR][/SIZE]
[SIZE=2][COLOR=black][FONT=Courier New] populateContactList();[/FONT][/COLOR][/SIZE][/LEFT]
[LEFT][SIZE=2][COLOR=black][FONT=Courier New] } [/FONT][/COLOR][B][COLOR=#7f0055][FONT=Courier New]catch[/FONT][/COLOR][/B][COLOR=black][FONT=Courier New] (Exception e) {[/FONT][/COLOR][/SIZE][/LEFT]
[LEFT][SIZE=2][COLOR=black][FONT=Courier New] Log.[I]e[/I]([/FONT][/COLOR][I][COLOR=#0000c0][FONT=Courier New]TAG[/FONT][/COLOR][/I][COLOR=black][FONT=Courier New], [/FONT][/COLOR][COLOR=#2a00ff][FONT=Courier New]"Exceptoin encoutered while deleting contact: "[/FONT][/COLOR][COLOR=black][FONT=Courier New] + e);[/FONT][/COLOR][/SIZE]
[SIZE=2][COLOR=black][FONT=Courier New] }[/FONT][/COLOR][/SIZE][/LEFT]
to delete i used this coding
Code:
[LEFT][COLOR=black][FONT=Courier New] ArrayList<ContentProviderOperation> ops = [/FONT][/COLOR][B][COLOR=#7f0055][FONT=Courier New]new[/FONT][/COLOR][/B][COLOR=black][FONT=Courier New] ArrayList<ContentProviderOperation>();[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] ops.add(ContentProviderOperation.[I]newDelete[/I](Data.[/FONT][/COLOR][I][COLOR=#0000c0][FONT=Courier New]CONTENT_URI[/FONT][/COLOR][/I][COLOR=black][FONT=Courier New])[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] .withSelection(Data.[/FONT][/COLOR][I][COLOR=#0000c0][FONT=Courier New]_ID[/FONT][/COLOR][/I][COLOR=black][FONT=Courier New] + [/FONT][/COLOR][COLOR=#2a00ff][FONT=Courier New]"=?"[/FONT][/COLOR][COLOR=black][FONT=Courier New], [/FONT][/COLOR][B][COLOR=#7f0055][FONT=Courier New]new[/FONT][/COLOR][/B][COLOR=black][FONT=Courier New] String[]{String.[I]valueOf[/I](name)})[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] .build());[/FONT][/COLOR]
[B][COLOR=#7f0055][FONT=Courier New]try[/FONT][/COLOR][/B][COLOR=black][FONT=Courier New] {[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] getContentResolver().applyBatch(ContactsContract.[/FONT][/COLOR][I][COLOR=#0000c0][FONT=Courier New]AUTHORITY[/FONT][/COLOR][/I][COLOR=black][FONT=Courier New], ops);[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] toast = Toast.[I]makeText[/I](ctx,[/FONT][/COLOR][COLOR=#2a00ff][FONT=Courier New]"Deleted"[/FONT][/COLOR][COLOR=black][FONT=Courier New], duration);[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] toast.show();[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] populateContactList();[/FONT][/COLOR][/LEFT]
[LEFT][COLOR=black][FONT=Courier New] } [/FONT][/COLOR][B][COLOR=#7f0055][FONT=Courier New]catch[/FONT][/COLOR][/B][COLOR=black][FONT=Courier New] (Exception e) {[/FONT][/COLOR][/LEFT]
[LEFT][COLOR=black][FONT=Courier New] Log.[I]e[/I]([/FONT][/COLOR][I][COLOR=#0000c0][FONT=Courier New]TAG[/FONT][/COLOR][/I][COLOR=black][FONT=Courier New], [/FONT][/COLOR][COLOR=#2a00ff][FONT=Courier New]"Exceptoin encoutered while deleting contact: "[/FONT][/COLOR][COLOR=black][FONT=Courier New] + e);[/FONT][/COLOR]
[COLOR=black][FONT=Courier New] }[/FONT][/COLOR][/LEFT]
i both add and delete i am not getting any error, but it is not reflected nither in the contact nor in the textView.
please help me , i am a newbie.
please help me , i am a newbie.