В моем приложении я анализирую канал из сети, как показано ниже:
private void downloadEpisodes(String Url) {
//Make Progress Bar Visible While Downloading Feed
progress_bar.setVisibility(ProgressBar.VISIBLE);
Log.d("CGRParser", "Downloading Feed");
//Start an ASync Thread to take care of Downloading Feed
new DownloadEpisodes().execute(Url);
}
private class DownloadEpisodes extends AsyncTask<String, Integer, ArrayList<LatestNews>> {
ArrayList<LatestNews> episodes;
@Override
protected ArrayList<LatestNews> doInBackground(String... url) {
//Download and Parse Feed
XmlFeedParser parser = new XmlFeedParser();
episodes = new ArrayList<LatestNews>();
episodes = parser.parse(url[0]);
return episodes;
}
@Override
protected void onPostExecute(ArrayList<LatestNews> result) {
//Feed has been Downloaded and Parsed, Display Data to User
Log.d("CGRParser", "Feed Download Complete");
displayEpisodes(result);
}
}
private void displayEpisodes(ArrayList<LatestNews> news_detail) {
//Create String Arrays to seperate titles and dates
Log.d("CGRParser", "Displaying News Titles To User");
ArrayList<String> episode_titles = new ArrayList<String>();
ArrayList<String> episode_description = new ArrayList<String>();
ArrayList<String> episode_link = new ArrayList<String>();
for (LatestNews news : news_detail) {
Log.d("News", "News Title: " + news.getTitle());
Log.d("News", "News Description: " + news.getDescription());
Log.d("News", "News Link: " + news.getLink());
episode_titles.add(news.getTitle());
episode_description.add(news.getDescription());
episode_link.add(news.getLink());
}
this.episode_titles = episode_titles;
this.episode_description = episode_description;
this.episode_link = episode_link;
//Create a ListAdapter to Display the Titles in the ListView
ListAdapter adapter = new ArrayAdapter<String>(this, R.layout.latest_news_row, R.id.title, episode_titles);
listview_news.setAdapter(adapter);
//Set Progress Bar Invisible since we are done with it
progress_bar.setVisibility(ProgressBar.INVISIBLE);
}
Теперь с этим кодом я хочу справиться с доступностью интернета. Если интернат недоступен, то сообщение должно отображаться как «Пожалуйста, проверьте интернатное соединение».
Пожалуйста, помогите мне в этом.
Спасибо.