0
我有一个RSS提要解析成列表视图在我的应用程序。我试图让它拉动rss中的每个项目的链接,并在单击列表视图中的项目时打开它。基本上我已经拥有了一切,但不知道在这个声明后我应该使用什么编码。onItemClick从RSS提要打开一个URL
公共无效onItemClick(适配器视图父,观景,INT位置,长的id){
我知道这是我的代码应该是打开被保存在RSS文件,但不知道如何网址从这里检索它。任何帮助是极大的赞赏。
公共类MainActivity扩展活动实现OnItemClickListener {
//RSS Feed URL
private final String CGR_FEED_URL = "http://www.mychurchevents.com/Calendar/RSS.ashx?days=7&ci=G1M7G1N8K5G1N8N8H2&igd=";
//XML Widgets
private ListView listview_episodes;
private ProgressBar progress_bar;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//XML Widgets by ID
listview_episodes = (ListView) findViewById(R.id.listview_episodes);
listview_episodes.setOnItemClickListener(this);
progress_bar = (ProgressBar) findViewById(R.id.progress_bar);
//Make Progress Bar Invisible
progress_bar.setVisibility(ProgressBar.INVISIBLE);
new ArrayList<String>();
new ArrayList<String>();
downloadEpisodes(CGR_FEED_URL);
}
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<Episode>> {
@Override
protected ArrayList<Episode> doInBackground(String... url) {
//Download and Parse Feed
XmlFeedParser parser = new XmlFeedParser();
ArrayList<Episode> episodes = new ArrayList<Episode>();
episodes = parser.parse(url[0]);
return episodes;
}
@Override
protected void onPostExecute(ArrayList<Episode> result) {
//Feed has been Downloaded and Parsed, Display Data to User
Log.d("CGRParser", "Feed Download Complete");
displayEpisodes(result);
}
}
private void displayEpisodes(ArrayList<Episode> episodes) {
//Create String Arrays to seperate titles and dates
Log.d("CGRParser", "Displaying Episode Titles To User");
ArrayList<String> episode_titles = new ArrayList<String>();
ArrayList<String> episode_dates = new ArrayList<String>();
for (Episode episode : episodes) {
Log.d("CGRParser", "Episode Title: " + episode.getTitle());
episode_titles.add(episode.getTitle());
episode_dates.add(episode.getDate());
}
//Create a ListAdapter to Display the Titles in the ListView
ListAdapter adapter = new ArrayAdapter<String>(this, R.layout.episode_row, R.id.title, episode_titles);
listview_episodes.setAdapter(adapter);
//Set Progress Bar Invisible since we are done with it
progress_bar.setVisibility(ProgressBar.INVISIBLE);
}
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
} `
我已经做到了这一点,并从来没有按照我需要的方式让它工作。我有XML解析就好了,一切都从使用另一个教程,并与我需要的东西修改它的工作。所有我需要的是要弄清楚如何使链接加载可能是一个webview后,我单击列表视图中的项目,但它需要加载链接从rss文件 – Bryan 2012-02-14 05:42:07
那么,你应该发布你的代码得到一个确切的想法,你做了什么,你在哪里面临的问题。 – 2012-02-14 05:43:30
你想让我发布所有代码,我很乐意发布它 – Bryan 2012-02-14 05:46:01