I want to have a loading icon that is displayed on top of where a RecyclerView would be, and disappear once the data is finished loading
It would look like:
Can anyone help me out?
I have the code which shows a TextView above the RecyclerView that says "Loading..." and disappears after the data is loaded, but the RecyclerView is still visible.
My XML:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/loaderTV"
android:text="Loading..."
android:layout_above="@+id/eventListRV"/>
<android.support.v7.widget.RecyclerView
android:scrollbars="vertical"
android:id="@+id/eventListRV"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/spinner">
</android.support.v7.widget.RecyclerView>
And then in my code
client.listCreators(request, new Callback<ServiceResponse<Event>>() {
@Override
public void success(ServiceResponse<Event> eventServiceResponse, Response response) {
eventList.addAll(eventServiceResponse.data.results);
Log.i("tag", String.valueOf(eventServiceResponse.data.total));
if (eventList.size() > 60) {
adapter.notifyDataSetChanged();
loadingText.setVisibility(View.GONE);
}
}
But I want the RecyclerView to be invisible while the data is loading and I want the progress bar ontop of where the RecyclerView is, and I don't want it to be a textview
match_parent
for width and height. recyclerView.setVisibility(View.GONE);
setVisibility(View.GONE)
, show your RecyclerView with setVisibility(View.VISIBLE)
and trigger a reload of the adapter with adapter.notifyDataSetChanged()
Recycler View.
Use RelativeLayout
. ProgressBar
prepare with android:layout_centerInParent="true"
.
<ProgressBar
android:id="@+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
At MainViewAdapter extends RecyclerView.Adapter<MainViewAdapter.MyViewHolder>
at onBindViewHolder
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, final int position) {
MainItem mainItem = mainItemList.get(position);
holder.getTextViewTitle().setText(mainItem.getNameMain());
//all your code here...
//After that display progressbar at the below
progressBar.setVisibility(View.GONE);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With