id属性为“android.R.id.list”的ListView;当我正确设置 ListView id 时出错

发布于 2024-10-28 12:49:59 字数 1786 浏览 7 评论 0原文

我有一个带有自定义适配器的列表视图。我收到标准

Your content must have a ListView whose id attribute is 'android.R.id.list'

错误,但是,我的 ListView 设置了 android:id="@android:id/list" 值。这真的让我很头疼。有什么建议吗?

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" style="@style/Layout">
    <ListView android:id="@android:id/list" style="@stlye/ListMenuView"></ListView>
</LinearLayout>

styles.xml

<resources>
    <style name="Layout" parent="@android:Theme">
        <item name="android:background">@drawable/background</item>
        <item name="android:scaleType">fitXY</item>
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">fill_parent</item>
        <item name="android:orientation">vertical</item> 
    </style>
    <style name="ListMenuView">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:cacheColorHint">#00000000</item>
    </style>
</resources>

我的 onCreate 方法:

/** Called when the activity is first created. */
@Override
public void onCreate( Bundle savedInstanceState ) {
    super.onCreate( savedInstanceState );
    setContentView( R.layout.main );

    m_menu = new ArrayList<ListItemData>();
    populateMenu();


    this.m_adapter = new ListMenuAdapter( this, R.layout.list_item, m_menu );

    setListAdapter(this.m_adapter);
}

有什么想法吗?

I have a Listview with a custom adapter. I am getting the standard

Your content must have a ListView whose id attribute is 'android.R.id.list'

error, however, My ListView has an android:id="@android:id/list" value set. It's really doing my head in. Any suggestions?

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" style="@style/Layout">
    <ListView android:id="@android:id/list" style="@stlye/ListMenuView"></ListView>
</LinearLayout>

styles.xml

<resources>
    <style name="Layout" parent="@android:Theme">
        <item name="android:background">@drawable/background</item>
        <item name="android:scaleType">fitXY</item>
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">fill_parent</item>
        <item name="android:orientation">vertical</item> 
    </style>
    <style name="ListMenuView">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:cacheColorHint">#00000000</item>
    </style>
</resources>

My onCreate method:

/** Called when the activity is first created. */
@Override
public void onCreate( Bundle savedInstanceState ) {
    super.onCreate( savedInstanceState );
    setContentView( R.layout.main );

    m_menu = new ArrayList<ListItemData>();
    populateMenu();


    this.m_adapter = new ListMenuAdapter( this, R.layout.list_item, m_menu );

    setListAdapter(this.m_adapter);
}

Any Ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

江心雾 2024-11-04 12:49:59

android:id="@android:id/list" 工作完美,我的问题是我有一个启动屏幕,它继承了一个继承 ListActivity 的基类,并且没有 <为闪屏活动定义的strong>ListView。我已将 SplashScreen 更改为仅继承 Activity。一切都按预期进行。

android:id="@android:id/list" works perfectly, My issue was I had a Splash screen that inherited a base class which was inheriting ListActivity and had no ListView defined for the splash screen activity. I have altered the SplashScreen to just inherit Activity. All works as expected.

枕头说它不想醒 2024-11-04 12:49:59

我面临着同样的问题。我扩展了 Activity 而不是 ListActivity 类,这解决了我的问题。

I was facing the same issue. I extende Activity instead of ListActivity class and this resolved my problem.

梦情居士 2024-11-04 12:49:59

您是说您使用自定义适配器,但从代码中我看不到这样的适配器。在这里你可以下载整个android项目,http://blog.sptechnolab .com/wp-content/uploads/2011/02/listBlog.zip

You are saying that you use custom adapter, but from code i can't see such adapter. Here you can download whole android project,http://blog.sptechnolab.com/wp-content/uploads/2011/02/listBlog.zip.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文