简体   繁体   English

如何解决在xml布局中的RecyclerView上消失的小部件?

[英]How to solve widgets disappearing on RecyclerView in xml layouts?

I have a RecyclerView which consist of items which has a radioButton... I want to refresh my RecyclerView items data after 2 seconds with showing a loading widget and make RecylerView to scroll to first item, while user clicks on RadioButtons. 我有一个RecyclerView ,它包含一个带有radioButton的项目...我想在2秒后刷新我的RecyclerView项目数据,显示加载小部件并让RecylerView滚动到第一个项目,同时用户点击RadioButtons。

Everything is done right except loading and RecylerView widget Visiblity ... 除了加载和RecylerView小部件Visiblity之外,一切都正常完成......

Loading widget and RecyclerView Visiblity don't change. 加载小部件和RecyclerView Visiblity不会更改。

This is My xml 这是我的xml

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recy_billing"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:layout_marginBottom="8dp"
            app:layout_constraintBottom_toTopOf="@+id/materialCardView7"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            />

        <com.airbnb.lottie.LottieAnimationView
            android:id="@+id/loading_order"
            android:layout_width="@dimen/loading"
            android:layout_height="@dimen/loading"
            android:layout_gravity="center"
            android:visibility="invisible"
            app:layout_constraintBottom_toTopOf="@id/materialCardView7"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:lottie_autoPlay="true"
            app:lottie_fileName="loading.json"
            app:lottie_loop="true" />

and this is my code.. 这是我的代码..

public void updateAddressSelectionRecy() {

    try {

        mRecyBilling.setVisibility(View.GONE);
        mSelectAddressLoading.setVisibility(View.VISIBLE);
        mRecyBilling.getAdapter().notifyDataSetChanged();
        mRecyBilling.scrollToPosition(0);

        Thread.sleep(SLEEP_TIME);
        mRecyBilling.setVisibility(View.VISIBLE);
        mSelectAddressLoading.setVisibility(View.GONE);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

}

Call mRecyBilling.getAdapter().notifyDataSetChanged(); 调用mRecyBilling.getAdapter().notifyDataSetChanged(); once again rigth before catch() block. catch()阻止之前再次严格。

ie: 即:

public void updateAddressSelectionRecy() {

    try {

        mRecyBilling.setVisibility(View.GONE);
        mSelectAddressLoading.setVisibility(View.VISIBLE);
        mRecyBilling.getAdapter().notifyDataSetChanged();
        mRecyBilling.scrollToPosition(0);

        Thread.sleep(SLEEP_TIME);
        mRecyBilling.setVisibility(View.VISIBLE);
        mSelectAddressLoading.setVisibility(View.GONE);
        mRecyBilling.getAdapter().notifyDataSetChanged();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM