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.

  • so what is the question then? What is a dataset? - Shwarz Andrei
  • @ShwarzAndrei Well, I snatched it out of the example to be honest) but as I understand it, if I use a list to display data, is it so that my list is not? - Inkognito
  • well then everything is essentially correct, it makes sense to check for null, so if (dataset! = null && dataset.isEmpty ()) {do something ...} - Shwarz Andrei
  • @ShwarzAndrei does not work, the list is displayed, but if for example I turn off the Internet and the list should not be displayed, then the inscription still does not come out, although in theory it should. Or if I swap the visible and gone in if, then only the textView is displayed - Inkognito
  • but the thing is, the fact is that the data you have already received at some point in time, and the fact that you turned off the Internet is a bit different, you just reformulate the question, saying to hide the list when the Internet disappeared, although who needs it? ) - Shwarz Andrei

0