如題所示。我做了一個 TabbedActivity 并在它下面實作了一個 ListView。我還制作了一個字串陣列以顯示在 Listview 中。
問題是:相同的文本將顯示在不同的選項卡上
例如:有兩個選項卡(number_decimal, number_roman),應該顯示(1,2,3) (I,II,III)
但是我執行之后,兩個頁面都顯示為1,2,3。
我該怎么做才能解決,謝謝。
另外,我應該提供哪個 Java 檔案?SectionPagerAdaptor ? PlaceHokderFragment ? 頁面視圖模型
如果有類似的問題,請告訴我。
下面是代碼(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>
uj5u.com熱心網友回復:
您需要在每個選項卡中使用一個片段,然后在每個片段中使用串列視圖而不是在其配接器中始終使用 recyclerview,串列視圖很愚蠢,并且大多數時候會產生奇怪的問題,尤其是當用戶滾動時
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/429939.html
