Home > Enterprise >  Android: Same Listview display different ArrayAdapter
Android: Same Listview display different ArrayAdapter

Time:02-03

As the topic shown. I made a TabbedActivity and implement an ListView under it. I also made an string array to display inside the Listview.

The problem is : Same text will display on different tabbed

For example: There are two tabbed (number_decimal, number_roman), It should display (1,2,3) (I,II,III)

But after I executed, both two pages are displayed 1,2,3.

What should I do to solve it, Thanks.

Also, Which Java file should I provide? SectionPagerAdaptor ? PlaceHokderFragment ? PageVIewModel

If there are similar questions, please let me know.

Belows are the code (XML) .

Here are the code (TabbedActivity and 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>

CodePudding user response:

you need to use one fragment inside each tab, then instead of list view inside of each fragment use always recyclerview whit its adapter, list view is stupid and most of time create strange problem, especially when user scrolls

  •  Tags:  
  • Related