popbackstack (null) сохраняет позицию просмотра прокрутки, устанавливая id - PullRequest
0 голосов
/ 10 февраля 2020

Я выполняю навигацию между двумя фрагментами в Android, используя Java.

Фрагмент A - Представление прокрутки содержит заголовок с видом повторного использования (извлечение данных из FireStore) Фрагмент B - Представление прокрутки содержит просмотры карт и представление повторного просмотра

Навигация: щелкнув элемент повторного просмотра и многое другое для фрагмента B. Нажмите кнопку «Назад» и popbackstack () для фрагмента A и сохраните предыдущую позицию прокрутки

Проблема: Когда я возвращаюсь назад, я не могу сохранить предыдущую позицию фрагмента А. Согласно сообщению Могу ли я сохранить положение ScrollView после возврата к предыдущему фрагменту, как ListView? , мне просто нужно установить идентификатор в моем представлении прокрутки. Фрагмент должен помочь мне сохранить состояние. Я пропускаю некоторые настройки в XML? Это потому, что я выбираю данные из FireStore, которые будут извлекать данные каждый раз, когда поступают фрагмент?

Фрагмент A XML:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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/CoordinatorLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ui.dashboard.DashboardFragment">


    <ScrollView
        android:id="@+id/scrollview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

        <LinearLayout
            android:id="@+id/LinearLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">


            <TextView
                android:id="@+id/tvTitle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="@dimen/padding_extra_large"
                android:text="@string/coinbalance"
                android:textColor="@color/colorPrimaryText"
                android:textSize="@dimen/text_size_ultra_large"
                android:textStyle="bold" />


            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recycler_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:nestedScrollingEnabled="false" />

        </LinearLayout>
    </ScrollView>


</androidx.coordinatorlayout.widget.CoordinatorLayout>

Фрагмент B XML

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/scrollview_detail"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <LinearLayout
        android:id="@+id/LinearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:focusableInTouchMode="true"
        android:orientation="vertical">


        <include

            android:id="@+id/include_note_item"
            layout="@layout/note_item" />

        <TextView
            android:id="@+id/title2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/margin_extra_large"
            android:fontFamily="sans-serif"
            android:gravity="left"
            android:lineSpacingExtra="8sp"
            android:text="@string/checkin_detail_rewards"
            android:textColor="@color/colorPrimaryText"
            android:textSize="@dimen/text_size_ultra_large"
            android:textStyle="bold" />

        <include

            android:id="@+id/include_viewpagercard"
            layout="@layout/viewpagercard" />

        <TextView
            android:id="@+id/subtitle3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/containerForPager"
            android:layout_margin="@dimen/margin_extra_large"
            android:focusableInTouchMode="true"
            android:fontFamily="sans-serif"
            android:gravity="left"
            android:lineSpacingExtra="8sp"
            android:text="@string/checkin_detail_activity"
            android:textColor="@color/colorPrimaryText"
            android:textSize="@dimen/text_size_ultra_large"
            android:textStyle="bold" />

        <include

            android:id="@+id/include_recyclerview"
            layout="@layout/recyclerview" />

        <Button
            android:id="@+id/btnWriteComment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/FrameCardView3"
            android:layout_marginStart="@dimen/margin_extra_large"
            android:layout_marginEnd="@dimen/margin_extra_large"
            android:layout_marginBottom="@dimen/margin_extra_large"
            android:background="@drawable/round_corner_button_secondary"
            android:backgroundTint="@color/colorAccent"
            android:clickable="true"
            android:focusable="true"
            android:foreground="?android:attr/selectableItemBackground"
            android:text="@string/social_comments_32"
            android:textAllCaps="false"
            android:textColor="@color/colorAccentLightText"
            android:textSize="@dimen/text_size_large" />
    </LinearLayout>
</ScrollView>
...