Android: 相同的Listview显示不同的ArrayAdapter
Android: Same Listview display different ArrayAdapter
如题所示。
我制作了一个 TabbedActivity 并在其下实现了一个 ListView。
我还制作了一个字符串数组以显示在 Listview 中。
问题是:相同的文本将显示在不同的选项卡上
例如:有两个标签(number_decimal, number_roman),
它应该显示 (1,2,3) (I,II,III)
但是我执行后,两个页面都显示1,2,3.
我该怎么做才能解决,谢谢。
Also,
Which Java file should I provide?
SectionPagerAdaptor ? PlaceHokderFragment ? PageVIewModel
如果有类似的问题,请告诉我。
下面是代码(XML).
这是代码(TabbedActivity 和 Listview):
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.main.PlaceholderFragment">
<!--
<TextView
android:id="@+id/section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginBottom="@dimen/activity_vertical_margin"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="@+id/constraintLayout"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintTop_creator="1" />
-->
<!-- 結帳 -->
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:entries="@array/vegetable">
</ListView>
<Button
android:id="@+id/button_jumptocash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="30dp"
android:layout_marginBottom="20dp"
android:text="@string/jumptocash"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
您需要在每个选项卡内使用一个片段,然后在每个片段内始终使用带有适配器的 recyclerview 而不是列表视图,
列表视图很愚蠢,大多数时候会产生奇怪的问题,尤其是当用户滚动时
如题所示。 我制作了一个 TabbedActivity 并在其下实现了一个 ListView。 我还制作了一个字符串数组以显示在 Listview 中。
问题是:相同的文本将显示在不同的选项卡上
例如:有两个标签(number_decimal, number_roman), 它应该显示 (1,2,3) (I,II,III)
但是我执行后,两个页面都显示1,2,3.
我该怎么做才能解决,谢谢。
Also, Which Java file should I provide? SectionPagerAdaptor ? PlaceHokderFragment ? PageVIewModel
如果有类似的问题,请告诉我。
下面是代码(XML).
这是代码(TabbedActivity 和 Listview):
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.main.PlaceholderFragment">
<!--
<TextView
android:id="@+id/section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginBottom="@dimen/activity_vertical_margin"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="@+id/constraintLayout"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintTop_creator="1" />
-->
<!-- 結帳 -->
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:entries="@array/vegetable">
</ListView>
<Button
android:id="@+id/button_jumptocash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="30dp"
android:layout_marginBottom="20dp"
android:text="@string/jumptocash"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
您需要在每个选项卡内使用一个片段,然后在每个片段内始终使用带有适配器的 recyclerview 而不是列表视图, 列表视图很愚蠢,大多数时候会产生奇怪的问题,尤其是当用户滚动时