2012-11-06 43 views
1

我是新来的android.I创建一个应用程序,并在该应用程序内,我正在考虑在活动的底部放置一个'marque Rss feed'。是否有可能?是否有可能在同一活动中放置两个以上的RSS提要?Marque Rss新闻提要里面我的android应用程序

+0

我建议看看Android支持库中的ViewPager,然后这个很棒的库:http://viewpagerindicator.com/ – mindvirus

回答

0

是有可能..

下面是代码要提取URL的RSS提要,并在Android的列表视图列出。

您需要先创建一个扩展ListActivity类,然后把这个代码:

// Initializing instance variables 
    headlines = new ArrayList(); 
    links = new ArrayList(); 

    try { 
     URL url = new URL("http://www.RSS-Feed-URL-HERE"); 

     XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); 
     factory.setNamespaceAware(false); 
     XmlPullParser xpp = factory.newPullParser(); 

      // We will get the XML from an input stream 
     xpp.setInput(getInputStream(url), "UTF_8"); 

      /* We will parse the XML content looking for the "<title>" tag which appears inside the "<item>" tag. 
      * However, we should take in consideration that the rss feed name also is enclosed in a "<title>" tag. 
      * As we know, every feed begins with these lines: "<channel><title>Feed_Name</title>...." 
      * so we should skip the "<title>" tag which is a child of "<channel>" tag, 
      * and take in consideration only "<title>" tag which is a child of "<item>" 
      * 
      * In order to achieve this, we will make use of a boolean variable. 
      */ 
     boolean insideItem = false; 

      // Returns the type of current event: START_TAG, END_TAG, etc.. 
     int eventType = xpp.getEventType(); 
     while (eventType != XmlPullParser.END_DOCUMENT) { 
      if (eventType == XmlPullParser.START_TAG) { 

       if (xpp.getName().equalsIgnoreCase("item")) { 
        insideItem = true; 
       } else if (xpp.getName().equalsIgnoreCase("title")) { 
        if (insideItem) 
         headlines.add(xpp.nextText()); //extract the headline 
       } else if (xpp.getName().equalsIgnoreCase("link")) { 
        if (insideItem) 
         links.add(xpp.nextText()); //extract the link of article 
       } 
      }else if(eventType==XmlPullParser.END_TAG && xpp.getName().equalsIgnoreCase("item")){ 
       insideItem=false; 
      } 

      eventType = xpp.next(); //move to next element 
     } 

    } catch (MalformedURLException e) { 
     e.printStackTrace(); 
    } catch (XmlPullParserException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

    // Binding data 
    ArrayAdapter adapter = new ArrayAdapter(this, 
      android.R.layout.simple_list_item_1, headlines); 

    setListAdapter(adapter); 


} 
public InputStream getInputStream(URL url) { 
     try { 
      return url.openConnection().getInputStream(); 
     } catch (IOException e) { 
      return null; 
     } 
    } 

@Override 
protected void onListItemClick(ListView l, View v, int position, long id) { 
    Uri uri = Uri.parse((String) links.get(position)); 
    Intent intent = new Intent(Intent.ACTION_VIEW, uri); 
    startActivity(intent); 
} 

&您也可以使类扩展了活动,并手动放两个列表视图,在活动&再处理这个代码为两个listViews。

+0

Thanx ...我会试试这个,让你知道:) –

相关问题