Issue
I'm developing an application that opens a Webview. But, when there is no Internet connexion, I would like to display an image saying "no internet connexion" instead of the webview. Is there a way of doing that ? I thought of setting the webview to "invisible" with the method setvisibility, is that ok ?
Solution
You can determine the status of internet connection using this.
ConnectivityManager cm =
(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null &&
activeNetwork.isConnectedOrConnecting();
And on the basis of the Boolean you can show different view in your application.
For hiding the webview you should use ViewStub. ViewStub are best for layout components that need not to be inflated everytime your activity inflate. ViewStub
For inflating the ViewStub you can use any of the setVisibility(View.VISIBLE) or findViewById(R.id.view_stub).inflate() .
Answered By - Amit Tripathi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.