gpt4 book ai didi

android - Recyclerview notifyDataSetChanged 再次进入同一 Activity 时未调用

转载 作者:行者123 更新时间:2023-11-29 15:33:59 25 4
gpt4 key购买 nike

在我的要求中有向导步骤。所以如果我在第二步。然后按后退。现在我在第一个向导中。然后按下一步以重新创建 Activity 。这就是我将其放入 OnCreate 的原因。

当我第一次参加该 Activity 时,我的适配器 notifydatasetchange 正常工作,但当我返回并再次参加同一 Activity 时Notifydatasetchange() 不工作意味着没有调用 onbindviewholder。

即使我尝试再次设置适配器,但仍未调用它。这是我的代码。我缺少什么?感谢您的帮助!

    protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.ProposalInviteOwnersView);
_lstviewNearByPeople = FindViewById<RecyclerView>(Resource.Id.lstviewNearByPeople);
_layoutmanager = new LinearLayoutManager(this, LinearLayoutManager.Horizontal, false);
_lstviewNearByPeople.HasFixedSize = true;
_lstviewNearByPeople.SetLayoutManager(_layoutmanager);
BindtoNearByAdapter();
}

public void BindtoNearByAdapter()
{
try
{
if (GlobalConst.LstNearByPeople.Count > 0)
{
_lstNearByPeople = new List<Owners>();
_lstNearByPeople.AddRange(GlobalConst.LstNearByPeople);

if(_nearByCollaboratorAdapter==null)
{
_lstviewNearByPeople.Visibility = ViewStates.Visible;

_nearByCollaboratorAdapter = new NearByCollaboratorAdapter(this, _lstNearByPeople, this, mlastPosition);
_lstviewNearByPeople.SetAdapter(_nearByCollaboratorAdapter);

}
else
{
_nearByCollaboratorAdapter.updateItems(_lstNearByPeople);

}

}
else
{
_noNearByDevicelayout.Visibility = ViewStates.Visible;
_lstviewNearByPeople.Visibility = ViewStates.Gone;
}


}
catch (System.Exception ex)
{
Core.Helpers.GlobalLogic.createCrashReport(ex);
Toast.MakeText(this, ex.Message.ToString(), ToastLength.Short).Show();
}
}

public class NearByCollaboratorAdapter : RecyclerView.Adapter
{
public List<Owners> _lstNearByPeople;
readonly ISelectCollaborator _listner;
readonly Activity _context;
protected int mLastPosition;


public NearByCollaboratorAdapter(Activity context, List<Owners> lstNearByPeople, ISelectCollaborator listner, int _mLastPosition)
{
_lstNearByPeople = lstNearByPeople;
_context = context;
_listner = listner;
mLastPosition = _mLastPosition;

}
public override int ItemCount => _lstNearByPeople.Count;

public void updateItems(List<Owners> lstNearByPeople)
{
_lstNearByPeople.Clear();
_lstNearByPeople.AddRange(lstNearByPeople);
this.NotifyDataSetChanged();
}






}

最佳答案

实现一个 onResume 方法...

@Override
public void OnResume (){
super.onResume();
BindtoNearByAdapter()
}

关于android - Recyclerview notifyDataSetChanged 再次进入同一 Activity 时未调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56395422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com