我有一个在NestedScrollView和ListView中包含一些静态TextView的布局,该布局应该在这些TextView下可见,并且可以与所有其他项目一起滚动。
所以我在NestedScrollView中添加了ListView,但问题是ListView中只显示第一个项目。
所有视图都在MaterialCardView中,布局如下:
<androidx.core.widget.NestedScrollView
android:id="@+id/sv_product_info"
android:layout_width="match_parent"
android:fillViewport="true"
android:layout_height="match_parent">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="20dp">
<include
android:id="@+id/product_id"
layout="@layout/layout_product_extras"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<include
android:id="@+id/product_description"
layout="@layout/layout_product_extras"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<include
android:id="@+id/product_purchase"
layout="@layout/layout_product_extras"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<include
android:id="@+id/product_price"
layout="@layout/layout_product_extras"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<include
android:id="@+id/product_unit_of_measeure"
layout="@layout/layout_product_extras"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<include
android:id="@+id/product_min_stock"
layout="@layout/layout_product_extras"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<include
android:id="@+id/product_vat"
layout="@layout/layout_product_extras"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<include
android:id="@+id/product_supplier"
layout="@layout/layout_product_extras"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ListView
android:id="@+id/list_extra"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="@layout/layout_product_extras" />
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.core.widget.NestedScrollView>
布局的主要目标是在其中显示此模型:
data class ProductWithDetails(
override var id: String,
override var description: String?,
override var unitOfMeasure: String,
override var purchase: Float,
override var price: Float,
override var quantity: Float,
var stock: List<Stock>,
var extra: List<Extra>,
var minStock: String,
var vat: String,
var supplier: String,
var priceOfUnit: String
) : Product(id, description, unitOfMeasure, purchase, price, quantity)
data class Stock(
var shop: Shop,
var quantity: String
)
ListView中应显示extra属性的位置。
在此之前,甚至其他字段都是ListView的一部分,但问题是,在其中一些字段上,我需要放置一个click方法并获取其值,而在布局中,该值必须以某种方式格式化。