简体   繁体   English

如何在ArrayAdapter创建的布局中显示其他textview等

[英]How do i display other textview etc in a layout created by an ArrayAdapter

hope someone can help. 希望有人可以帮忙。 My activity extends ListView and in OnCreate creates an ArrayAdapter. 我的活动扩展了ListView,并在OnCreate中创建一个ArrayAdapter。 The custom ArrayAdapter class i've written then in its getView function creates each list item to have a textview and checkbox. 然后,我在其getView函数中编写的自定义ArrayAdapter类将创建每个列表项以具有textview和复选框。 It does this by inflating a separate layout. 它通过扩大单独的布局来做到这一点。 Which effectively means the layout for the activity is never used. 这实际上意味着从未使用活动的布局。 This all works fine. 这一切都很好。 But ideally i'd also have a textview before this list and a button after it. 但理想情况下,我在此列表之前还要有一个textview,之后还有一个按钮。 How/where do i add these!?! 我如何/在哪里添加这些!!

See this link for the details: http://developer.android.com/reference/android/app/ListActivity.html 有关详细信息,请参见此链接: http : //developer.android.com/reference/android/app/ListActivity.html

It explains how to do exactly what you are asking for, use a custom view for the activity and still use the ListActivity class. 它说明了如何精确地执行您要的操作,如何为活动使用自定义视图以及仍然使用ListActivity类。

Screen Layout 屏幕布局

ListActivity has a default layout that consists of a single, full-screen list in the center of the screen. ListActivity具有默认布局,该布局由位于屏幕中央的单个全屏列表组成。 However, if you desire, you can customize the screen layout by setting your own view layout with setContentView() in onCreate(). 但是,如果需要,可以通过使用onCreate()中的setContentView()设置自己的视图布局来自定义屏幕布局。 To do this, your own view MUST contain a ListView object with the id "@android:id/list" (or list if it's in code) 为此,您自己的视图必须包含ID为“ @android:id / list”(或列表,如果在代码中,则为List)的ListView对象

Optionally, your custom view can contain another view object of any type to display when the list view is empty. (可选)您的自定义视图可以包含另一个任何类型的视图对象,以在列表视图为空时显示。 This "empty list" notifier must have an id "android:id/empty". 此“空列表”通知程序必须具有ID“ android:id / empty”。 Note that when an empty view is present, the list view will be hidden when there is no data to display. 请注意,如果存在空白视图,则在没有数据可显示时列表视图将被隐藏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM