showing progress bar during data loading

XamarinNewcomerXamarinNewcomer USMember ✭✭
edited February 2019 in Xamarin.Android

I have a fragment that has a recyclerview that'll be loading data from an API and I want it to show a progress bar when it's loading and when paging starts.

but the progress view I made is not firing on the fragment, The loading view works great on the login activity so not sure why it's working on the fragment.

(sorry for the poor formatting, the forum doesn't seem to like code formatting much)

My recyclerview layout:

<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/feed_refreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
android:id="@+id/feed_rbFeed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/very_light_gray"
android:paddingBottom="80dp"
android:clipToPadding="false" />
</android.support.v4.widget.SwipeRefreshLayout>

the progress view
<?xml version="1.0" encoding="utf-8"?>

        <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:indeterminate="true"
            style="?android:attr/progressBarStyleLarge"/>
    </RelativeLayout>

my code firing the progress:

    protected override async void SetData()
    {
        // this is actually called in a function, this is just for show.
        container.BringToFront();
        container.Visibility = ViewStates.Visible;

        // load my data code.

        container.Visibility = ViewStates.Gone;
    }

I've seen other people suggest you add a null entry to the viewholder and detect that to add the progressbar and then remove it, but that sounds horrible and hacky as hell.

I just need it to appear when the bottom is reached on the recyclerview and while I'm fetching data.

Best Answer

  • XamarinNewcomerXamarinNewcomer US ✭✭
    Accepted Answer

    after finding nothing else, I'm using the null entry approach, it works for now, I'll revisit a better solution later on

Answers

  • jezhjezh Member, Xamarin Team Xamurai

    What's code of the container ?
    Could you please post the code of the ProgressBar and the steps how you using it in the fragment?

  • XamarinNewcomerXamarinNewcomer USMember ✭✭

    container is the linearlayout that the progressbar is housed at, you'd see it if this forum wasn't awful at handling code (tried 3 times and it cut it off each time >:( )

    the progressbar is in a linearlayout that's hidden, when I want to show it I just make the container visible, this works just fine with my activities but not my fragments.

  • XamarinNewcomerXamarinNewcomer USMember ✭✭
    Accepted Answer

    after finding nothing else, I'm using the null entry approach, it works for now, I'll revisit a better solution later on

Sign In or Register to comment.