Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add delete functionality (not working totally).

  • Loading branch information...
commit a43ac34e4aa482bee6c74a32edecdac7b7afde46 1 parent f81d1c4
Gianluca Pacchiella authored
View
3  AndroidManifest.xml
@@ -4,6 +4,7 @@
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.READ_CONTACTS" />
+ <uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-sdk android:minSdkVersion="8" />
@@ -21,4 +22,4 @@
</activity>
</application>
-</manifest>
+</manifest>
View
8 res/layout/main.xml
@@ -3,6 +3,12 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
+ <Button
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="delete"
+ android:onClick="doDelete"
+ />
<ListView
android:id="@android:id/list"
@@ -24,4 +30,4 @@
android:layout_height="wrap_content"
/>
-</LinearLayout>
+</LinearLayout>
View
23 src/org/ktln2/android/ContractContactsManager/ContractContactsManagerActivity.java
@@ -16,6 +16,8 @@
import android.support.v4.content.CursorLoader;
import android.support.v4.app.FragmentActivity;
+import android.net.Uri;
+
// TODO: http://thinkandroid.wordpress.com/2010/01/13/writing-your-own-contentprovider/
@@ -44,6 +46,16 @@
private SimpleCursorAdapter mRawContactsAdapter;
private SimpleCursorAdapter mDataContactsAdapter;
+ /*
+ * TODO: create arrays
+ */
+ private Uri[] URIs = new Uri[] {
+ ContactsContract.Contacts.CONTENT_URI,
+ ContactsContract.Groups.CONTENT_URI,
+ ContactsContract.RawContacts.CONTENT_URI,
+ ContactsContract.Data.CONTENT_URI,
+ };
+
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -149,6 +161,17 @@ public void onNothingSelected(AdapterView parent) {
getSupportLoaderManager().initLoader(ID_RAW_CONTACTS, null, this);
getSupportLoaderManager().initLoader(ID_DATA, null, this);
}
+
+ public void doDelete(View view) {
+ long[] ids = mListView.getCheckedItemIds();
+
+ for (long id : ids) {
+ android.util.Log.i(TAG, "deleting " + URIs[mID]+ " id: " + id);
+ int nDeleted = getContentResolver().delete(URIs[mID], "_id = '" + id + "'", null);
+ android.util.Log.i(TAG, "deleted: " + nDeleted);
+ }
+
+ }
/**
*
Please sign in to comment.
Something went wrong with that request. Please try again.