現在、「無限」のリスト ビュー (URL からのデータの読み込みとカスタム アダプターへの保存) を作成するための非同期の画像の読み込みで少し問題が発生しています。基本的にkoush/UrlImageViewHelperへのポートであるImageViewへのこの拡張メソッドを見つけました、しかし、オリジナルは頻繁に更新され、ポートは現在9か月間更新されていません...カスタムアダプターにImageViewを入力しているとき、すべてが正常に高速に動作しているようです(小さな画像をダウンロードしていますかなり高速なサーバー) ですが、約 200 個の画像 (それぞれのサイズが 15 ~ 20 kb) の後、ダウンロードが停止します。画像のキャッシュに問題があると思いますが、拡張機能で提供されている「Cleanup」メソッドを使用しても何も変わりません。誰かがそれを修正する方法を知っていますか、またはそのタスクに対するより良い解決策を持っていますか? 独自の「キュー」を作成しようとしましたが、別の問題があります。リストビューをスクロールすると、新しい ImageView には既にソース画像があり、正しい画像に変更されますが、高速スクロールすると非常に見栄えが悪くなります。これが私のコードです:
カスタム リスト アダプターの GetView
public override View GetView(int position, View convertView, ViewGroup parent)
{
//Populating the adapter with new items
if (position >= this._items.Count - 1)
ThreadPool.QueueUserWorkItem(o => this.LoadPage());
var item = this._items[position];
View view = convertView;
if (view == null)
view = this._context.LayoutInflater.Inflate(Resource.Layout.CustomRowView, null);
var imgUrl = string.Format(@"http://myserver.com/?action={0}&url={1}", "get.thumbnail", item.Image.Url);
//Here is the image loading row
view.FindViewById<ImageView>(Resource.Id.imageView1).SetUrlDrawable(imgUrl);
view.FindViewById<TextView>(Resource.Id.txtTitle).Text = item.Title;
view.FindViewById<TextView>(Resource.Id.txtYear).Text = item.Information.Year;
view.FindViewById<TextView>(Resource.Id.txtGenre).Text = item.Information.Genre;
view.FindViewById<TextView>(Resource.Id.txtGrade).Text = item.Rating.Grade;
view.FindViewById<TextView>(Resource.Id.txtVotes).Text = string.Format("( {0} )", item.Rating.Votes);
return view;
}
LoadPage 関数
public void LoadPage()
{
OnUpdateAnimeListStart(); //Event to display loading message
try
{
this._items.FillListFromUrl(string.Format("http://myserver.com/page/{0}/", this._page));
}
catch(Exception ex)
{
_context.RunOnUiThread(() =>
{
new AlertDialog.Builder(_context)
.SetPositiveButton("Ok", (sender, args) =>
{
Intent blankIntent = new Intent();
blankIntent.SetFlags(ActivityFlags.ClearTop);
int intPID = Android.OS.Process.MyPid();
Android.OS.Process.KillProcess(intPID);
})
.SetMessage(ex.Message)
.SetTitle("Error!")
.Show();
});
}
this._page++;
_context.RunOnUiThread(() =>
{
_context.FindViewById<ListView>(Resource.Id.listView).InvalidateViews();
});
OnUpdateAnimeListEnd(); //Event to hide loading message
}
そして、これは私が話した代替の「キュー」です。
public class ImageDownloader
{
private List<ImageView> _queueImageViews;
private List<string> _queueImageUrls;
private Activity _context;
public ImageDownloader(Activity context)
{
this._context = context;
this._queueImageViews = new List<ImageView>();
this._queueImageUrls = new List<string>();
}
public void DownloadImage(ImageView imgView, string url)
{
this._queueImageViews.Add(imgView);
this._queueImageUrls.Add(url);
if (this._queueImageViews.Count == 1)
this._startJob();
}
private void _startJob()
{
WebClient web = new WebClient();
web.DownloadDataCompleted += new DownloadDataCompletedEventHandler(web_DownloadDataCompleted);
web.DownloadDataAsync(new Uri(this._queueImageUrls[0]));
}
private void _removeFromeQueue(int index = 0)
{
this._queueImageUrls.Remove(this._queueImageUrls[index]);
this._queueImageViews.Remove(this._queueImageViews[index]);
}
void web_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
{
ImageView v = this._queueImageViews[0];
this._context.RunOnUiThread(() =>
{
Bitmap bm = BitmapFactory.DecodeByteArray(e.Result, 0, e.Result.Length);
v.SetImageBitmap(bm);
});
this._removeFromeQueue();
if (this._queueImageViews.Count > 0)
this._startJob();
}
}
前もって感謝します。