我有3个片段的viewpager。然后在片段3中,我使用singleValueEventListener向Firebase数据库查询数据。 但是问题是当我从Firebase数据库更新片段3中的数据时。然后打开应用程序,数据不会直接更新。我需要打开和关闭应用3次,然后数据才会更新。
另一种更新数据的情况是,我必须转到片段3-片段1-然后返回片段3。然后数据将被更新。
然后在片段3中,我刷卡刷新。要刷新数据,我还需要在数据更新之前先滑动2次
@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container,
Bundle savedInstanceState) {
v = inflater.inflate(R.layout.fragment_three, container, false);
userRef = FirebaseDatabase.getInstance().getReference("user_course");
users = FirebaseAuth.getInstance().getCurrentUser();
mataKuliahRef = FirebaseDatabase.getInstance().getReference("courses");
daftarPengumumanRef = FirebaseDatabase.getInstance().getReference("pengumuman");
pengumumanRef = FirebaseDatabase.getInstance().getReference("pengumuman_course");
mFlagPengumuman = FirebaseDatabase.getInstance().getReference("flag_pengumuman");
swipeLayout = (SwipeRefreshLayout) v.findViewById(R.id.swiperefresh);
View b= ((MainActivity)getActivity()).tabThree;
badge = new BadgeView(getActivity(), b);
badge.setBadgeMargin(90,0);
badge.setTextSize(10);
swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
new Handler().postDelayed(new Runnable() {
@Override public void run() {
swipeLayout.setRefreshing(false);
listPengumuman.clear();
consolidatedList.clear();
LoadDataPengumuman();
}
private void onLoaded() {
swipeLayout.setEnabled(true);
swipeLayout.setRefreshing(false);
}
}, 500);
}
});
counter = new Counter() {
@Override
public void setCounter(int count) {
Log.e("Ser_Counter", "total countnya " + asd);
Log.e("Ser_Counter", "masuk count ");
asd=asd+count;
if(asd==0){
Log.e("Ser_Counter", "masuk asd=0");
badge.hide();
}else{
Log.e("Ser_Counter", "masuk asd=else");
badge.setText(asd + "");
badge.show();
}
}
};
mJumlahPengumuman = (TextView) v.findViewById(R.id.jumlah_pengumuman);
mRecyclerView = (RecyclerView) v.findViewById(R.id.PengumumanRView);
mRecyclerView.setHasFixedSize(true);
adapter = new myAdapterPengumuman(getActivity().getApplicationContext(), consolidatedList,counter);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity().getApplicationContext());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mRecyclerView.setLayoutManager(layoutManager);
RecyclerViewHeader header = (RecyclerViewHeader) v.findViewById(R.id.header3);
header.attachTo(mRecyclerView);
mRecyclerView.setAdapter(adapter);
LoadDataPengumuman();
return v;
}
我不知道这是怎么了,请帮忙。
答案 0 :(得分:0)
您不能从Fragment-1更改Fragment-3的数据,因为ViewPager只能激活Fragment-2。
假设您在第5页上,ViewPager只能激活第4页,而第6页则不能激活其他页面。