Reputation: 1023
Right now, I'm getting some values to fill a recyclerView with the following list adapter through binding:
private val otrosSubmitListAdapter = OtrosSubmitListAdapter()
[more code]
binding.otrosRequestList.adapter = otrosSubmitListAdapter
Problem is that I'd like to, when all values have been binded, merge then with some other values, I'd like to make the merge in a variable called DummyContent.ITEMS, which I would later put a new filterAdapter and use that adapter for my recyclerview, like this:
dataArray = DummyContent.ITEMS
filter_adapter = MyFilterAdapter(this.activity, dataArray)
recyclerView.adapter = filter_adapter
Problem is that I cannot grasp a way for waiting so OtrosSubmitListAdapter() has completed all its internal binding and I can get its values properly, right now by using this code DummyContents have never the values needed from OtrosSubmitListAdapter() to be merged, so only its other values can be properly shown.
What would be a possible way to wait for OtrosSubmitListAdapter() to complete all its binding and getting to properly use the results?
Upvotes: 0
Views: 297
Reputation: 279
Create a callback inside your OtrosSubmitListAdapter like this:
public interface AdapterCallback {
void itemsBound();
}
Add it to your activity
public class MainActivity extends AppCompatActivity implements AdapterCallback
Pass a reference of AdapterCallback to OtrosSubmitListAdapter when you are initializing it
On your adapter
AdapterCallback adapterCallback;
public OtrosSubmitListAdapter(AdapterCallback adapterCallback){
this.adapterCallback = adapterCallback;
}
@Override
public void onBindViewHolder(final OtrosSubmitListAdapter.MyViewHolder holder, final int position) {
if (position == itemList.size() - 1){
adapterCallback.itemsBound();
}
}
On your activity
private val otrosSubmitListAdapter = OtrosSubmitListAdapter(this)
@Override
public void itemsBound() {
//enter code here
}
see https://stackoverflow.com/a/32032990/11881779 for adapter callback example
Edit : If I understood your question wrong, please share code of your adapter and activity
Upvotes: 1