2013-03-22 44 views
0

我有两个工作的RSS提要。两者都像预期的那样更新,但是我的第一个rss feed是可滚动的,并允许点击每个文章(当时出现浏览器)。我只是想知道如果我错过了一些重要的事情,或者我做错了?RSS Feed不滚动或打开浏览器?

private class MyTask extends AsyncTask<Void, Void, Void>{ 

       @Override 
       protected Void doInBackground(Void... arg0) { 
        try { 
         URL rssUrl1 = new URL("http://rss"); 
         SAXParserFactory mySAXParserFactory = SAXParserFactory.newInstance(); 
         SAXParser mySAXParser = mySAXParserFactory.newSAXParser(); 
         XMLReader myXMLReader = mySAXParser.getXMLReader(); 
         RSSHandler myRSSHandler = new RSSHandler(); 
         myXMLReader.setContentHandler(myRSSHandler); 
         InputSource myInputSource = new InputSource(rssUrl1.openStream()); 
         myXMLReader.parse(myInputSource); 
         myRssFeed = myRSSHandler.getFeed(); 



         ///URL rssUrl1 = new URL("http://rss"); 
         URL rssUrl = new URL("http://www.midlandsireland.ie/news.rss"); 
         SAXParserFactory mySAXParserFactory1 = SAXParserFactory.newInstance(); 
         SAXParser mySAXParser1 = mySAXParserFactory1.newSAXParser(); 
         XMLReader myXMLReader1 = mySAXParser1.getXMLReader(); 
         RSSHandler myRSSHandler1 = new RSSHandler(); 
         myXMLReader1.setContentHandler(myRSSHandler1); 
         InputSource myInputSource1 = new InputSource(rssUrl.openStream()); 
         myXMLReader1.parse(myInputSource1); 
         myRssFeed1 = myRSSHandler1.getFeed(); 

        } catch (MalformedURLException e) { 
         e.printStackTrace();  
        } catch (ParserConfigurationException e) { 
         e.printStackTrace();  
        } catch (SAXException e) { 
         e.printStackTrace(); 
        } catch (IOException e) { 
         e.printStackTrace();  
        } 
        return null; 
       } 

       @Override 
       protected void onPostExecute(Void result) { 
        if (myRssFeed!=null && myRssFeed1!=null) { 
         ArrayAdapter<RSSItem> adapter = 
           new ArrayAdapter<RSSItem>(getApplicationContext(), 
             android.R.layout.simple_list_item_1, myRssFeed.getList()); 
              setListAdapter(adapter); 

         ArrayAdapter<RSSItem> adapter1 = 
           new ArrayAdapter<RSSItem>(getApplicationContext(),    
             android.R.layout.simple_list_item_1,myRssFeed1.getList()); 
         ListView lv = (ListView) findViewById(R.id.list1); 
         lv.setAdapter(adapter1); 
        } 
        else 
        { 
        setListAdapter(new ArrayAdapter<RSSItem>(getApplicationContext(),    
          android.R.layout.simple_list_item_1, new ArrayList<RSSItem>())); 

        ArrayAdapter<RSSItem> adapterEmpty1 = 
           new ArrayAdapter<RSSItem>(getApplicationContext(),    
             android.R.layout.simple_list_item_1, new ArrayList<RSSItem>()); 
         ListView lv = (ListView) findViewById(R.id.list1); 
         lv.setAdapter(adapterEmpty1); 
        } 
        super.onPostExecute(result); 
       } 
      } 
      @Override 
    protected void onListItemClick(ListView l, View v, int position, long id) {  
       Uri feedUri = Uri.parse(myRssFeed.getItem(position).getLink()); 
       Intent myIntent = new Intent(Intent.ACTION_VIEW, feedUri); 
       startActivity(myIntent); 
      } 

     } 

我试图添加工作饲料到第二个饲料位置,所以我认为它的事情与listview或textview?你们有什么感想?


protected void onPostExecute(Void result) { 
        if (myRssFeed!=null && myRssFeed1!=null) { 
         ArrayAdapter<RSSItem> adapter = 
           new ArrayAdapter<RSSItem>(getApplicationContext(), 
             android.R.layout.simple_list_item_1, myRssFeed.getList()); 
              setListAdapter(adapter); 

         ArrayAdapter<RSSItem> adapter1 = 
           new ArrayAdapter<RSSItem>(getApplicationContext(),    
             android.R.layout.simple_list_item_1,myRssFeed1.getList()); 
              ListView lv = (ListView) findViewById(R.id.list1); 
               lv.setAdapter(adapter1); 
               lv.setOnItemClickListener(mListener); 


               ListView lv.OnItemClickListener mListener = new OnItemClickListener() { 
                @Override 
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
                 Uri feedUri1 = Uri.parse(myRssFeed1.getItem(position).getLink()); 
                 Intent myIntent1 = new Intent(Intent.ACTION_VIEW, feedUri1); 
                 startActivity(myIntent1);     
                }; 
               } 





        } 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/tableLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="@color/white"> 

    <fragment 
     android:id="@+id/map" 
     android:layout_width="300dp" 
     android:layout_height="413dp" 
     android:layout_marginTop="5dp" 
     android:layout_toRightOf="@+id/button5" 
     class="com.google.android.gms.maps.MapFragment" /> 



    <Button 
     android:id="@+id/button3" 
     android:layout_width="305dp" 
     android:layout_height="100dp" 
     android:layout_marginLeft="34dp" 
     android:layout_marginTop="10dp" 
     android:onClick="ClickTourismButton" 
     android:layout_below="@+id/map" 
     android:text="Touism Guide" /> 
    <TextView 
     android:id="@+id/button5" 
     android:layout_width="34dp" 
     android:textIsSelectable="true" 
     android:layout_height="match_parent" 
     android:background="@color/grey" 
     /> 
    <TextView 
     android:id="@+id/button6" 
     android:layout_width="34dp" 
     android:textIsSelectable="true" 
     android:layout_alignParentRight="true" 
     android:layout_height="match_parent" 
     android:background="@color/grey" 
     /> 
    <Button 
     android:id="@+id/button4" 
     android:layout_width="305dp" 
     android:layout_height="100dp" 
     android:layout_marginLeft="34dp" 
     android:layout_below="@+id/button3" 
     android:text="Whats Nearby" /> 
    <Button 
     android:id="@+id/button2" 
     android:layout_width="305dp" 
     android:layout_height="100dp" 
     android:layout_marginLeft="34dp" 
     android:layout_below="@+id/button4" 
     android:text="Favouites" /> 
    <Button 
     android:id="@+id/button1" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="304dp" 
     android:layout_marginLeft="34dp" 
     android:layout_height="100dp" 
     android:layout_below="@+id/button2" 
     android:text="See Full Map" /> 

    <TextView 
     android:layout_width="260dp" 
     android:layout_height="413dp" 
     android:layout_marginLeft="10dp" 
     android:layout_marginTop="5dp" 
     android:textIsSelectable="true" 
     android:layout_toRightOf="@+id/map" 
     android:layout_toLeftOf="@+id/button6" 
     android:id="@+id/feedupdate1" /> 

    <ListView 
     android:id="@android:id/list" 
     android:background="@color/red" 
     android:layout_toRightOf="@+id/map" 
     android:layout_width="260dp" 
     android:layout_marginTop="5dp" 
     android:layout_marginLeft="10dp" 
     android:layout_height="413dp" /> 

    <TextView 
     android:id="@+id/empty" 
     android:textIsSelectable="true" 
     android:layout_width="260dp" 
     android:layout_height="413dp" 
     android:layout_marginLeft="10dp" 
     android:layout_marginTop="5dp" 
     /> 
    <ListView 

     android:id="@+id/list1" 
     android:background="@color/blue" 
     android:layout_toRightOf="@+id/button3" 
     android:layout_width="260dp" 
     android:layout_marginTop="430dp" 
     android:layout_marginLeft="6dp" 
     android:layout_height="390dp" /> 
    <TextView 
     android:id="@+id/feedupdate" 
     android:layout_width="260dp" 
     android:layout_height="390dp" 
     android:layout_marginLeft="6dp" 
     android:layout_marginTop="430dp" 
     android:textIsSelectable="true" 
     android:layout_toRightOf="@+id/button3" 
     /> 



</RelativeLayout> 
+0

你的第二个饲料不起作用? – Luksprog 2013-03-22 12:17:04

+0

它的工作原理,它更新并显示新的文章。然而,它不允许我滚动或点击像我以前的RSS饲料的文章。 – PropK 2013-03-22 14:42:40

回答

0

您似乎使用ListActivity,管理一个ListView部件。在此之后,您在Activity中使用的onListItemClick回拨将仅适用于由ListActivity(ID为android.R.id.list)管理的ListView。对于其他ListView,您需要设置自己的OnItemClickeListener。例如:

// a field in your ListActivity 
OnItemClickListener mListener = new OnItemClickListener() { 
    @Override 
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
     // do the stuff for the second list feed     
    } 
} 

设置该OnItemClickListener关于你的第二ListView监听某个事件在你的代码(如onPostExecute法):

// ... 
ArrayAdapter<RSSItem> adapter1 = new ArrayAdapter<RSSItem>(getApplicationContext(), android.R.layout.simple_list_item_1,myRssFeed1.getList()); 
ListView lv = (ListView) findViewById(R.id.list1); 
lv.setAdapter(adapter1); 
lv.setOnItemClickListener(mListener); 
// the rest of the code... 
+0

我现在不断收到错误,“void是变量OnItemClickListener的无效类型”OnItemClickListener无法解析为类型 – PropK 2013-03-22 15:20:44

+0

@JosephKenny请导入OnItemClickListener类(在Eclipse中为CTRL + SHIFT + O)。还要确保'mListener'是'Activity'中的一个字段(在公共类等下面声明)。{')。 – Luksprog 2013-03-22 15:26:04

+0

@JosephKenny你已经删除了以前的代码,出现错误的原因是“lv.OnItemClickListener ....'?另外,如果您不能滚动第二个提要,则使用两个ListView使用的布局。 – Luksprog 2013-03-22 16:05:49