I display in my activation the data that I receive. Added an "empty" view to activity_main.xml if data will not be displayed.
Xml code:
<android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="vertical" /> <TextView android:id="@+id/empty_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="@string/no_data_available" android:visibility="gone" /> Now I try to prescribe a condition under which elements will be displayed depending on the data mapping:
private void initViews() { recyclerView.setLayoutManager(new LinearLayoutManager(this)); topStoriesAdapter = new TopStoriesAdapter(models, this); recyclerView.setAdapter(topStoriesAdapter); if (topStories.isEmpty()) { recyclerView.setVisibility(View.VISIBLE); emptyView.setVisibility(View.GONE); } else { recyclerView.setVisibility(View.GONE); emptyView.setVisibility(View.VISIBLE); } } The list is displayed correctly, but if you swap places in if 'e VISIBLE with GONE places, then only TextView will be displayed. The problem is that for example, if I turn off the Internet, then the data that I get from the server should not be loaded, but for some reason the TextView in this case is not displayed, tell me what I'm doing wrong.