id属性为“android.R.id.list”的ListView;当我正确设置 ListView id 时出错
我有一个带有自定义适配器的列表视图。我收到标准
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
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.我面临着同样的问题。我扩展了 Activity 而不是 ListActivity 类,这解决了我的问题。
I was facing the same issue. I extende Activity instead of ListActivity class and this resolved my problem.
您是说您使用自定义适配器,但从代码中我看不到这样的适配器。在这里你可以下载整个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.