我在\资源创建的文件\布局名为contactlist.xml为什么我的自定义布局文件无法识别?
但它不是在我的代码确认:
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 });
我想创建一个自定义布局,对于每个联系人有三个复选框。
为什么我的自定义布局不被接受为有效?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 更新2012年2月9日:
终于来了!
随着stackOverflowers的帮助和这篇文章:http://www.vogella.de/articles/AndroidListView/article.html
我终于得到了它的工作;像往常一样,一旦你理解了一些概念,这并不难。它归结为使用这种代码,这是我恳求/借入/偷走,并适于:
@Override 公共无效的onCreate(捆绑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);
}
...,并确保 “ondemandandautomatic_authorize”(或任何你命名你的布局文件)是这样的(未完成的,但你的想法):
<?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>
......并将“R.id.contactLabel”替换为“R.id.”
显然,还有很多事情要做,但是一个巨大的障碍已经被阻止。
指定清单中的内容? – 2012-02-07 16:38:06