I created a file in \res\layout named contactlist.xml
But it is not recognized in my code:
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this,
//android.R.layout.simple_list_item_1, mContacts, //if cre8 own layout, replace "simple_[etc]"
//android.R.layout.simple_list_item_checked, mContacts, // or simple_list_item_multiple_choice
//android.R.layout.simple_list_item_multiple_choice, mContacts,
android.R.layout.contactlist, mContacts, // <- contact list ist xml-non-grata
new String[] { ContactsContract.Contacts.DISPLAY_NAME },
new int[] { android.R.id.text1 });
I want to create a custom layout that for each Contact has three checkboxes.
Why is my custom layout not accepted as valid?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Updated 2/9/2012:
Finally!
With the help of stackOverflowers and this article: http://www.vogella.de/articles/AndroidListView/article.html
I finally got it working; as usual, it's not that tough once you grok a couple of concepts. It boils down to using this sort of code, which I begged/borrowed/stole and adapted:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
// Return all contacts, ordered by name
String[] projection = new String[] { ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME };
mContacts = managedQuery(ContactsContract.Contacts.CONTENT_URI,
projection, null, null, ContactsContract.Contacts.DISPLAY_NAME);
// Display all contacts in a ListView
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this,
R.layout.ondemandandautomatic_authorize, mContacts,
new String[] { ContactsContract.Contacts.DISPLAY_NAME },
new int[] { R.id.contactLabel });
setListAdapter(mAdapter);
}
...and making sure "ondemandandautomatic_authorize" (or whatever you name your layout file) is something like this (unfinished, but you get the idea):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1" />
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2" />
<CheckBox
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3" />
<TextView
android:id="@+id/contactLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="(replace this)"
android:textSize="20px" >
</TextView>
</LinearLayout>
...and that "R.id.contactLabel" is replaced with "R.id."
There's more to be done, obviously, but a big obstacle has been hurdled.