2012-02-14 66 views
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) { 




} 

} `

回答

1

我只想堅持要經過thisTutorial並下載完整的源代碼,並得到它的工作。這將清除你的查詢,它是如何工作的,並且它還包括使用幾個你將學習到的XML(SAX,DOM,XmlPullParser,其他一些)

UPDATE:

您可以使用getSelectedItemPosition(),並從ListView選定的值。然後進行展示RSS的進一步過程。

public void onItemClick(AdapterView<?> parent, View view, int position, 
                     long id) { 
      // get the selected item and do the further process 
      listview.getItemAtPosition(position); 
} 
+0

我已經做到了這一點,並從來沒有按照我需要的方式讓它工作。我有XML解析就好了,一切都從使用另一個教程,並與我需要的東西修改它的工作。所有我需要的是要弄清楚如何使鏈接加載可能是一個webview後,我單擊列表視圖中的項目,但它需要加載鏈接從rss文件 – Bryan 2012-02-14 05:42:07

+0

那麼,你應該發佈你的代碼得到一個確切的想法,你做了什麼,你在哪裏面臨的問題。 – 2012-02-14 05:43:30

+0

你想讓我發佈所有代碼,我很樂意發佈它 – Bryan 2012-02-14 05:46:01