我在recyclerView
方法上有一个onCreateView
。但我必须填写我在onResume
方法上收到的值。问题是onCreateView
在onResume
之前开始。我该怎么办?
答案 0 :(得分:1)
onCreateView在适配器中,你可以在onResume中创建一个适配器,
然后setAdapter
在onResume里面进行recyclerview。
每次你可以使用某种布尔局部变量来避免创建它,它会告诉你是否已经创建了适配器。
@Override
protected void onResume() {
super.onResume();
if (adapterNotCreated) {
adapter = new RecyclerAdapter(this, data)
daysRecyclerView.setAdapter(adapter);
daysRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
}
}
类似的东西。
答案 1 :(得分:0)
您应该通过在onResune中调用notifidatasetchsnged而不是setAdapter来更新适配器的数据,这应该在onCreateView中完成