我有一個ListView
和SimpleCursorAdapter
。 我對SimpleCursorAdapter
代碼如下所示:如何在後臺生成縮略圖?
private void listenAdapterErstellen()
{
adapter = new SimpleCursorAdapter(this, R.layout.my_listlayout,
MainController.getInstance().getMyCursor(db),
new String[] {"Foo", "Test"},
new int[] {R.id.imageViewFoo, R.id.textViewTest}, 0);
adapter2.setViewBinder(new ViewBinder() {
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if (columnIndex == 1) {
ImageView imageView = (ImageView) view;
String Pic = cursor.getString(1);
if (Pic != null) {
File file = new File(Pic);
if (file.exists()) {
imageView.setImageBitmap(MainController.getInstance().generateBitmap(Pic, SessionActivity.this));
}
} else {
imageView.setImageResource(R.drawable.ic_launcher);
}
return true;
}
if (columnIndex == 2) {
...
}
return false;
}
});
}
的問題是,在我的MainController.getInstance().generateBitmap()
它產生一個小的位圖需要大量的時間。所以加載列表需要一些時間。
如何在後臺爲列表生成圖像並立即顯示列表然後添加圖片?
http://stackoverflow.com/questions/541966/how-do-i-do-a-lazy-load-of-images-in-listview嘗試鏈接中的線程。包含優秀的源代碼示例 – 2013-04-30 15:29:34
我需要他們做的東西,但不是在互聯網上的文件中,而是在設備上的文件。無論如何發佈這個答案,我會接受它 – gurehbgui 2013-04-30 17:05:16