see the NetworkUtils class to see how to get data from internet.
//Hiding the keyboard after the button pressed.
InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputManager != null) {
inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
//Getting the network info and connectivity state:
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = null;
if (connectivityManager != null) {
networkInfo = connectivityManager.getActiveNetworkInfo();
}
if (networkInfo != null && networkInfo.isConnected() && SEARCH_QUERY.length() != 0) {
//Updating the text iews so that the user know what is going on.
titleTextview.setText(R.string.loading);
authorTetview.setText(R.string.please_wait);
//Ask for the data over internet
new FetchBook(titleTextview, authorTetview).execute(SEARCH_QUERY);
} else {
if (SEARCH_QUERY.length() == 0) {
authorTetview.setText("");
titleTextview.setText(R.string.no_search_term);
} else {
authorTetview.setText("");
titleTextview.setText(R.string.no_connection);
}
}