I load the data from the server in batches. New portions are loaded when scrolling the screen. I AsyncTask using AsyncTask .
During loading, a progressBar and TextView "loaading.." appear at the bottom of the screen TextView "loaading.."
I wanted to handle the situation when it is impossible to load the data - in this case, the message " failed to load data " should appear below and the " try again " button should appear.
Here is the layout :

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <!-- Список --> <ListView android:id=" @android :id/list" android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="#ffffffff" /> <!-- Панель для прогресс-бара и для проверки подгрузки данных--> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0" android:background="#ffffffff" android:orientation="horizontal" > <ProgressBar android:id="@+id/progress_bar" style="?android:attr/progressBarStyleLarge" android:layout_width="42dip" android:layout_height="42dip" /> <TextView android:id="@+id/progress_bar_text" android:layout_width="fill_parent" android:layout_marginLeft="15dip" android:gravity="center_vertical" android:layout_height="wrap_content"/> <Button android:id="@+id/try_again_button" android:visibility="invisible" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Try again"> </Button> </LinearLayout> </LinearLayout> 

How to implement alternation of progressBar and buttons for reloading?

  • @StasOn, please correct the name of your question - make it more specific than just "How to implement?". - Stanislav Pankevich

2 answers 2

yes, that's about it. But now the problem is that the button is invisible. Added android: visibility = "invisible" for the button, but it didn't help much - now, while everything is fine, at the bottom just a white bar remains under that layout, which should have a button

You can also set the GONE parameter, then the view is removed from the markup, and accordingly the other elements will change accordingly, as if the first one were not at all. That is, you set the bar (laity) Gone, then it disappears and the page is stretched to the bottom of the screen, But as a load, again visible and the sheet I twist will rise and a bar will appear below.

    Suppose you have a function that downloads data from the server and returns some sort of ArrayList <> . It does it all in doInBackground () AsyncTask`a .

    If the Internet has fallen off, then make it return null .

    In onPostExecute I would check for result == null - yes, show the button, no - add data to the adapter

    • yes, that's about it. But now the problem is that the button is invisible. Added android: visibility = "invisible" for the button, but it didn't help much - now, while everything is fine, at the bottom just a white bar remains under that layout, in which there should be a button - Stas0n
    • as written below, use visibility = "gone" - Roman Zakharov
    • @Roman Zakharov, and how to make it so that if it still happens that you could not load the data and check it on onPostExecute, then when you clicked on the button, the data loading method was repeated again? - Stas0n