I have a question in 2 parts.
1) How can I populate my ListView so that the rows are displayed, but when the items are selected, the value of the invisible identifier (contact identifier from telephone contacts) is the value that is actually used?
2) I have a ListView that uses multipleChoice mode to select items. He replenished with the names from my contact list. When I select an item in a ListView, I want this selected item to call my SqLite routine to store the value in a database record. How to make this event fire when an item is marked in the list?
This is my XML layout;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@+id/lvContacts"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:choiceMode="multipleChoice"
/>
</LinearLayout>
And here is the code that I use to populate my ListView;
private void fillData() {
final ArrayList<String> contacts = new ArrayList<String>();
lvContacts = (ListView) findViewById(R.id.lvContacts);
String[] proj_2 = new String[] {Data._ID, Phone.DISPLAY_NAME, CommonDataKinds.Phone.TYPE};
cursor = managedQuery(Phone.CONTENT_URI, proj_2, null, null, null);
while(cursor.moveToNext()) {
if ( cursor.getInt(2) == Phone.TYPE_MOBILE ) {
String name = cursor.getString(1);
contacts.add(name);
}
}
final ArrayAdapter<String> aa;
aa = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice,
contacts);
aa.sort(new Comparator<String>() {
public int compare(String object1, String object2) {
return object1.compareTo(object2);
};
});
lvContacts.setAdapter(aa);
}
, - onClick , .
. .