所以我准备好了我的浏览器活动,但是我正在努力让代码工作以打开我的 rss 提要中的链接以在其中打开,它只是进入一个空白页面。我尝试了很多东西,但没有任何效果。所以我最终回到了本教程中使用的标准代码http://www.itcuties.com/android/how-to-write-android-rss-parser/。我以 engadget 提要为例,看看我是否可以让它工作。这是我的听众活动
public class ListListener implements OnItemClickListener {
// List item's reference
List<RssItem> listItems;
// Calling activity reference
Activity activity;
public ListListener(List<RssItem> aListItems, Activity anActivity) {
listItems = aListItems;
activity = anActivity;
}
/**
* Start a browser with url from the rss item.
*/
public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(listItems.get(pos).getLink()));
activity.startActivity(i);
}
}
这是我的 engadgetfeed 活动
public class EngadgetFeed extends Activity {
private EngadgetFeed local;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_engadget_feed);
// Set reference to this activity
local = this;
GetRSSDataTask task = new GetRSSDataTask();
// Start download RSS task
task.execute("http://www.engadget.com/rss.xml");
// Debug the thread name
Log.d("Engadget", Thread.currentThread().getName());
}
private class GetRSSDataTask extends AsyncTask<String, Void, List<RssItem> > {
@Override
protected List<RssItem> doInBackground(String... urls) {
// Debug the task thread name
Log.d("Engadget", Thread.currentThread().getName());
try {
// Create RSS reader
RssReader rssReader = new RssReader(urls[0]);
// Parse RSS, get items
return rssReader.getItems();
} catch (Exception e) {
Log.e("Engadget", e.getMessage());
}
return null;
}
@Override
protected void onPostExecute(List<RssItem> result) {
// Get a ListView from main view
ListView endgadgetfeed = (ListView) findViewById(R.id.listMainView);
// Create a list adapter
ArrayAdapter<RssItem> adapter = new ArrayAdapter<RssItem> (local,R.layout.simple_list_item_1, result);
// Set list adapter for the ListView
endgadgetfeed.setAdapter(adapter);
// Set list view item click listener
endgadgetfeed.setOnItemClickListener(new ListListener(result, local));
}
}
}
任何帮助,将不胜感激