0

Currently I have strange problems that remind me of working with the WPF Dispatcher from earlier times. In WPF my workaround was to increase the dispatcher invoke priority.

In Xamarin Android I work around this issue by calling

uiProgressBar.Invalidate(); uiProgressBar.RequestLayout();

at specific stages to force and update.

A short description of my scenario:

I am using a ListView. Every list element has a ProgressBar. When I start updating serveral ProgressBar's in parallel the GUI descides to stop updating the progress after some time but keeps responsive to touch events, pan, etc.

I am working with async await.

I have also noticed that the problem mainly occures when using Release Mode with the option "Bundle assemblies into native code".

Hopefully someone can help me, or tell me if this is a bug or expected behavior. Thank you for help in advance.

smedasn
  • 1,249
  • 1
  • 13
  • 16

1 Answers1

1

Hopefully someone can help me, or tell me if this is a bug or expected behavior. Thank you for help in advance.

For any data changes inside a ListView, you should use adapter.NotifyDataSetInvalidated(); to let ListView update all the items. I don't see your detailed codes, so what I can provide is just an Example:

ProgressBarAdapter.cs:

public class ProgressBarAdapter:BaseAdapter
{
    Context _context;
    public List<Model> _items;
    public ProgressBarAdapter(Context context,List<Model> items)
    {
        _context = context;
        _items = items;
    }

    public override int Count => _items.Count;

    public override Java.Lang.Object GetItem(int position)
    {
        return _items[position];
    }

    public override long GetItemId(int position)
    {
        return _items[position].id;
    }

    public override View GetView(int position, View convertView, ViewGroup parent)
    {
        ProgressBar bar = null;
        if (convertView != null)
        {
            bar = convertView as ProgressBar;
        }
        else
        {
            bar=(ProgressBar)(_context as MainActivity).LayoutInflater.Inflate(Resource.Layout.ListViewItem,null);
        }

        bar.Progress = _items[position].value;
        return bar;
    }
}

If you want to change the data, instead of accessing the Android View directly, you should simply change the _items of Adapter:

adapter._items= InitList(20);
private List<Model> InitList(int start=0)
{
    List<Model> list = new List<Model>();
    for (int i = start; i < 50; i++)
    {
        list.Add(new Model {
            id=i,
            value=i
        });
    }
    return list;
}

And call NotifyDataSetInvalidated:

adapter.NotifyDataSetInvalidated();
Elvis Xia - MSFT
  • 10,801
  • 1
  • 13
  • 24