2013-09-28 84 views
0

所以我準備好了我的瀏覽器活動,但是我努力讓代碼工作從我的rss提要打開鏈接打開它,它只是空白頁。我嘗試了很多東西,但沒有任何工作。所以我最終回到了本教程http://www.itcuties.com/android/how-to-write-android-rss-parser/中使用的標準代碼。我使用engadget飼料作爲例子,看看我能否得到它的工作。這裏是我的listlistener活動rss饋入到自定義瀏覽器活動而不是普通瀏覽器

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

那麼什麼我不得不這樣做,我在月球上回答我自己的問題是:

,而不是具有下列

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);    
} 

所以我希望這可以幫助其他人誰具有相同的。