我正在收集youtube的gdata API中的數據並希望使用視頻的縮略圖。我已經有了每個縮略圖的網址,但是我無法讓圖像顯示在我的列表視圖中。位圖當前不返回null,但是我無法用我當前的實現(我知道的?)調用imageview.setImageBitmap(bitmap)
方法。請幫助,如果你知道更好的方式來做到這一點!由於從列表視圖適配器中加載URL中的圖像
public class ResultListActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String searchquery = null;
Intent starter = getIntent();
Bundle extras = starter.getExtras();
if (extras != null) {
searchquery = extras.getString("search");
}
final String URL = "http://gdata.youtube.com/feeds/api/videos?max-results=5&alt=json&author=user&q=" + searchquery;
final ArrayList<HashMap<String, ?>> data = new ArrayList<HashMap<String, ?>>();
final QueryYoutube query;
query = new QueryYoutube();
boolean success = query.searchYoutube(URL);
if (success == false) {
Toast.makeText(this, "Sorry, no matching results found.", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(ResultListActivity.this, YoutubeActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
finish();
}
int size = query.getNumberResults();
HashMap<String, Object> row = new HashMap<String, Object>();
for (int i=0; i<size; i++) {
Bitmap bitmap = null;
Drawable d = null;
try {
bitmap = BitmapFactory.decodeStream((InputStream)new URL(query.getThumbnail(i)).getContent());
bitmap.setDensity(Bitmap.DENSITY_NONE);
d = new BitmapDrawable(bitmap);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
row = new HashMap<String, Object>();
row.put("Thumbnail", d);
row.put("Title", query.getTitle(i));
row.put("Description", query.getDescription(i));
data.add(row);
}
SimpleAdapter adapter = new SimpleAdapter(this, data, R.layout.row,
new String[] {"Thumbnail","Title","Description"},
new int[] {R.id.thumb, R.id.title, R.id.description});
setListAdapter(adapter);
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent lVideoIntent = new Intent(null, Uri.parse("ytv://"+query.getVideoID(position)),
ResultListActivity.this, OpenYouTubePlayerActivity.class);
startActivity(lVideoIntent);
}
});
}
}
我得到了的getContent()方法是未定義類型烏里 – Greg 2012-03-23 14:51:38