所以我准备好了我的浏览器活动,但是我很难让代码工作从我的RSS源打开链接打开,它只是一个空白页面。我尝试了很多东西,但没有任何工作。所以我最终回到了本教程http://www.itcuties.com/android/how-to-write-android-rss-parser/中使用的标准代码。我使用engadget feed作为示例,看看我是否可以使它工作。这是我的listlistener活动
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));
}
}
}
任何帮助将不胜感激
答案 0 :(得分:0)
我必须做的事情,以及我在月球上回答我自己的问题,是以下几点;
而不是以下:
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);
}
我用过:
public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
Uri uri;
String stringuri;
stringuri = (Uri.parse(listItems.get(pos).getLink())).toString();
Intent i = new Intent(activity, Browser2.class);
i.putExtra(EXTRA_MESSAGE, stringuri);
activity.startActivity(i);
}
所以我希望这有助于其他拥有同样的人。