我最近在代码中发生了一些非常奇怪的事情。我的android应用程序有一个带有viewpager的tablayout设置。每个选项卡都包含一个recyclerview。第一个选项卡具有片段“FeedFragment”,其具有带有适配器“FeedAdapter”的recyclerview设置,第三个选项卡具有片段“NotificationFragment”,其具有设置了回收器视图的“NotificationAdapter”的recyclerview设置。 问题是,当我转到通知选项卡时,每次调用FeedAdapter的“OnBindViewHolder”方法。我不知道为什么会发生这种情况因为我的代码中没有任何内容可以实现。这是我的NotificationFragment类的代码:
ISharedPreferences pref = Application.Context.GetSharedPreferences("UserInfo", FileCreationMode.Private);
string userName = pref.GetString("Username", String.Empty);
// Use this to return your custom view for this Fragment
// return inflater.Inflate(Resource.Layout.YourFragment, container, false);
DBRepository dbr = new DBRepository();
notifications = dbr.GetNotificationMember(userName);
View view = inflater.Inflate(Resource.Layout.notificationsView, container, false);
empty = view.FindViewById<TextView>(Resource.Id.empty);
//pb.Visibility = ViewStates.Visible;
notifitem = view.FindViewById<RecyclerView>(Resource.Id.rv);
notifitem.HasFixedSize = true;
if (notifications.Count == 0)
{
empty.Visibility = ViewStates.Visible;
}
else
{
empty.Visibility = ViewStates.Gone;
}
layoutmanager = new LinearLayoutManager(Activity);
adapter = new NotificationAdapter(notifications, Activity);
notifitem.SetLayoutManager(layoutmanager);
notifitem.SetAdapter(adapter);
return view;
从NotificationFragment返回视图后立即调用OnBindViewHolder方法。知道为什么会这样吗?