我有两个工作 RSS 提要。两者都像预期的那样更新,但是我的第一个 rss 提要是可滚动的,并且允许单击每篇文章(然后出现浏览器)。我只是想知道我是否错过了一些重要的事情或者我做错了?
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);
}
}
我尝试将工作提要添加到第二个提要位置,所以我认为它与列表视图或文本视图有关?你们有什么感想?
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>