为什么我的自定义布局文件无法识别? [英] Why is my custom layout file not recognized?

查看:136
本文介绍了为什么我的自定义布局文件无法识别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我\\水库中创建的文件\\名为contactlist.xml布局

I created a file in \res\layout named contactlist.xml

但它不是我的code公认的:

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?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
已更新2012年2月9日:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Updated 2/9/2012:

终于来了!

随着stackOverflowers的帮助和这篇文章: http://www.vogella.de /articles/AndroidListView/article.html

With the help of stackOverflowers and this article: http://www.vogella.de/articles/AndroidListView/article.html

我终于得到了它的工作;像往常一样,它一旦你神交几个概念不是那么强硬。它归结为使用这种code的,我求/借用/窃取和适应:

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:

@覆盖
公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);

@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);

}

...并确保ondemandandautomatic_authorize(或任何你命名你的布局文件)是这样的(未完成的,但你的想法):

...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>

...这R.id.contactLabel替换为R.id。

...and that "R.id.contactLabel" is replaced with "R.id."

还有更多的工作要做,很明显,但一个很大的障碍已经被翻过。

There's more to be done, obviously, but a big obstacle has been hurdled.

推荐答案

这应该是

R.layout.contactlist

而不是

android.R.layout.contactlist

Android是当你正在使用的系统资源使用。

android is used when you are using the system resources.

这篇关于为什么我的自定义布局文件无法识别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆