have ContactListActivity class as below
public class ContactListActivity extends ListActivity{
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
getListView().setFocusable(true);
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
String[] from = new String[]
{ContactsContract.Contacts.DISPLAY_NAME,ContactsContract.Contacts.HAS_PHONE_NUMBER,ContactsContract.Contacts._ID};
int[] to = new int[] {R.id.name};
ContactListCursorAdapter adapter = new
ContactListCursorAdapter(getApplicationContext(), R.layout.listview,
getCursor(), from, to);
setListAdapter(adapter);
}
Where ContactListCursorAdapter looks as below
public class ContactListCursorAdapter extends SimpleCursorAdapter{
private Context context;
private int layout;
private Cursor c;
public ContactListCursorAdapter (Context context, int layout,
Cursor c, String[] from, int[] to) {
super(context, layout, c, from, to);
this.context = context;
this.layout = layout;
this.c = c;
}
@Override
public Cursor runQueryOnBackgroundThread(CharSequence constraint)
{
String[] projection = new String[] {
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.Contacts.HAS_PHONE_NUMBER,
ContactsContract.Contacts._ID
};
return
context.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
projection, null, null, null);
}
}
listview xml looks as below
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"/>
<TextView
android:id="@+id/number"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_below="@id/name"
android:layout_alignBottom="@id/number"
android:textSize="15sp"/>
<CheckBox android:text=""
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignRight="@id/name"
android:layout_alignParentRight="true"/>
</RelativeLayout>
My contact list with checkbox is prepared correctly. however when I
check an item from the list (using check box) and then continuing
scrolling up or down, it "checks"/"selects" other items(randomly) as
well. I think first chekecked item's id is preserved and everytime it
creates new view and "selects/checks" other items with same id or
something? When I uncheck any of those indirectly selected items it
unselcts all of them together. Strongly it appers to be an "id" issue?
Thanks,
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en