一切都已完成,即创建适配器,创建布局并传递数据但是当我将ListView添加到主活动时,则不会显示任何内容。我认为问题出在xml中。请帮忙
Activity2.xml
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.student.shopifysalespediasample.Activity2"
android:orientation="vertical"
android:id="@+id/list"
android:drawSelectorOnTop="true">
<!-- android:drawSelectorOnTop="true" shows a visual effect while clicking on listItem views-->
它显示空白屏幕,而不是在xml中显示示例列表项
工具:listitem |工具:listheader |工具:listfooter
这些属性适用于<AdapterView>
(及其子类,如<ListView>
和<RecyclerView>
),用于指定应作为列表项,页眉或页脚在该适配器内绘制的布局。例如,我们的Contacts + app的fragment_contacts_xml
布局声明了<RecyclerView>
,这就是添加tools:listitem=”@layout/contact_item”
之前和之后的样子
工具:ITEMCOUNT
此属性仅适用于<RecyclerView>
,用于指定布局编辑器在布局预览中应呈现的列表项数。
默认情况下,Android Studio会显示
<RecyclerView>
的10个列表项。
因此,通常在添加tools:listitem
属性后,<RecyclerView>
将覆盖整个布局屏幕,您将无法再看到其下方的其他视图元素。在这种情况下,tools:itemCount
属性将帮助您查看<RecyclerView>
下方的元素。
您可以在hidden gems article找到更多。
您需要添加ArrayAdapter或CustomAdapter以及列表项布局以填充列表视图。如果在添加适配器问题后仍然存在则请分享完整代码。使用此链接作为参考。 https://www.vogella.com/tutorials/AndroidListView/article.html