Aris Guimerá Aris Guimerá - 4 months ago 17
Android Question

Get values onResume method

I have a

recyclerView
on
onCreateView
method. But I have to fill with values that i receive on
onResume
method. The problem is
onCreateView
start before
onResume
. What can I do?

Answer

onCreateView is in adapter, and you can create an adapter in onResume, and then setAdapter for recyclerview inside onResume.

Also to avoid creating it every time you can use some kind of boolean local variable which will tell you if the adapter was already created.

@Override
protected void onResume() {
    super.onResume();
    if (adapterNotCreated) {
        adapter = new RecyclerAdapter(this, data)
        daysRecyclerView.setAdapter(adapter);
        daysRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
    }
}

Something like that.

Comments