how to get the checked contact from listview?
i want to save the contacts from a list view wen i check my check box. i
am new to android i Google and found that view holder is used but didn't
understand it properly please tell me how can i get all checked contacts.
Thanks.
package com.example.assignmentapp;
import android.app.Activity;
import android.app.ListActivity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.support.v4.widget.SimpleCursorAdapter;
import android.util.Log;
import android.widget.CheckBox;
import android.widget.ListView;
public class ContactActivity extends Activity
{
ListView listContacts;
CheckBox checkbox;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.contact_list);
String[] projection = new String[]
{ContactsContract.CommonDataKinds.Phone._ID,
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER};
// Get content provider and cursor
ContentResolver cr = getContentResolver();
Cursor cursor =
cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,projection,
null, null, null);
// Let activity manage the cursor
startManagingCursor(cursor);
Log.d("", "cursor.getCount()=" + cursor.getCount());
// Get the list view
ListView listView = (ListView) findViewById(android.R.id.list);
String[] from = { ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME};
int[] to = { R.id.text1};
SimpleCursorAdapter adapter;
adapter=new SimpleCursorAdapter(this, R.layout.row, cursor,from,to);
listView.setAdapter(adapter);
checkbox=(CheckBox)findViewById(R.id.checkbox1);
}
}
No comments:
Post a Comment