I'm trying to do what I thought it was a simple task: implementing a fragment that display different views based on internet availability. To be clear: try to start youtube app without connectivity, you will see a beautiful error screen with a 'Retry' button. When you click the button the fragment (of just the view, or something else) reloads and, if internet is now available, display the correct items. I have two fragments inside a ViewPager. the one fragment have recyclerview and it retrieve data from firebase.I want the first fragment to display an error message and a 'Retry' button. When the button is pressed, just like the youtube app does, I want to reload the content of the fragments and display the correct stuff, if the network is available. I don't know how can I do this.enter image description here Please help!
Fragment_1.java
public View onCreateView(LayoutInflater inflater, ViewGroup group, Bundle b)
{
View view=inflater.inflate(R.layout.fragment_home,group,false);
recyclerView=(RecyclerView)view.findViewById(R.id.recyclerview);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(view.getContext()));
myref= FirebaseDatabase.getInstance().getReference().child("/Blog");
FirebaseRecyclerAdapter<Blog,BlogViewHolder> recyclerAdapter=new FirebaseRecyclerAdapter<Blog,BlogViewHolder>(
Blog.class,
R.layout.individual_row,
BlogViewHolder.class,
myref
) {
@Override
protected void populateViewHolder(BlogViewHolder viewHolder, Blog model, int position) {
viewHolder.setTitle(model.getTitle());
viewHolder.setDescription(model.getDescription());
viewHolder.setImage(model.getImage());
}
};
recyclerView.setAdapter(recyclerAdapter);
return view;
}
}