私にとってうまくいったのは、投稿されたランナブルとしてではなく、mPagerAdapter.notifyDataSetChanged()の後にmPager.setCurrentItemを呼び出すことでした。
次に例を示します(MonoDroidの場合)。
public void UpdateDetialsView(string type)
{
string typeName4 = Java.Lang.Class.FromType(typeof(ParcelRecordComplaintDetailsView)).Name;
if (_fragments.Count > 3)
{
_fragments.RemoveAt(_fragments.Count - 1);
////////////////////////////////////////////////////////////
// Called here it wasn't working for me (Posted or not)
//_viewPager.Post(new Action(() => { _viewPager.SetCurrentItem(3, true); }));
}
_fragments.Add(Fragment.Instantiate(Activity, typeName4));
_pagerAdapter.NotifyDataSetChanged();
////////////////////////////////////////////////////////////
// Called here it works as expected
_viewPager.SetCurrentItem(3, true);
}
どこ
protected MyAdapter _pagerAdapter;
protected ViewPager _viewPager;
private List<Android.App.Fragment> _fragments;
と
public class MyAdapter : Android.Support.V13.App.FragmentStatePagerAdapter
{
private List<Fragment> _fragments;
public override Java.Lang.Object InstantiateItem(View p0, int p1)
{
return base.InstantiateItem(p0, p1);
}
public MyAdapter(Android.App.FragmentManager fm) : base(fm)
{
}
public MyAdapter(Android.App.FragmentManager fm, List<Android.App.Fragment> fragments) : base(fm)
{
_fragments = fragments;
}
public override int Count
{
//get { return FRAG_PAGES; }
get { return _fragments.Count; }
}
public override Android.App.Fragment GetItem(int p0)
{
return _fragments[p0];
}
public override float GetPageWidth(int p0)
{
//return base.GetPageWidth(p0);
return (float) (0.5f);
}
public override int GetItemPosition(Java.Lang.Object p0)
{
//return base.GetItemPosition(p0);
return PagerAdapter.PositionNone;
}
}