I want to know the _ID of the loaded document_ because I have a button that when pressed, this creates a subcollection in the document. For this reason I would like to know how to _get the ID of the loaded document_ so that I can operate my button correctly.
I'm using the _FirestorePagingAdapter_ tool.
@itzThiefz-exe, You can get DocumentReference of loaded documents by -
DocumentReference ref = getItem(position).getReference();
Then, you can call getId() method to get it's ID as..
String id = ref.getId()
Thank you very much sir, I hope you can also help me with my other problem.
@itzThiefz-exe Sure. Welcome!
How can I get the number of objects loaded?
I would like to make an (IF) that when the recyclerview has 0 objects loaded it shows a custom (Layout) that says it has no objects . I could achieve it with Firebase UI Realtime Database , but with FIrebase UI Firestore I can not do it .
I'm using the FirestorePagingAdapter tool.
@itzThief Rather than this, you can override method onLoadingStateChanged. Then you can update layout when state becomes LOADED
@Override
protected void onLoadingStateChanged(@NonNull LoadingState state) {
switch (state) {
case LOADING_INITIAL:
// The initial load has begun
// ...
case LOADING_MORE:
// The adapter has started to load an additional page
// ...
case LOADED:
// The previous load (either initial or additional) completed
// ...
case ERROR:
// The previous load (either initial or additional) failed. Call
// the retry() method in order to retry the load operation.
// ...
}
}
But how could I know if 0 objects were loaded or not?
@itzThiefz-exe I think PagingAdapter is having a method size() to get size. You can try it.
I'm trying but without results, if it's not too much trouble sir, could you give me an example please?
Suppose you have FirestorePagingAdapter instance as mAdapter. In your activity, write the below code where you want to implement your feature.
if(mAdapter.size() == 0) {
//Do your changes
}
when I put the code adapter.size () this does not recognize the method .size ()
Ok. I will let you know. Wait for some time.
Thank you very much sir, I appreciate your help.
Sorry. Actually it's my mistake. I referred PagingAdapter documentation hence I told you about method size().
Now, try above code for your feature...
if(mAdapter.getItemCount() == 0) {
//Do your changes
}
Mm works well, but the problem is that I've seen that first check that there are no items and do the action, then verify that there are items and do the action, in summary, do the two actions at the same time, How I can avoid this? :smile:
Can't get it. Please explain in brief or explain with example.
Well, I'm putting my code in the override method onLoadingStateChanged.
case LOADED:
if (adapter.getItemCount() == 0 {
Toast.... "No items"
} else {
Toast..... "Items Found"
}
break;
My problem is that first it shows that there are no items, after loading the items shows that if there are items, but with a small delay, why does this happen?
Why putting code inside case of LOADED? Because when items are loaded then size will never 0. Instead, put code inside case LOADING_MORE.
Can you tell me what exactly you want to achieve?
If you want to show another layout which displays "NO OBJECTS" when there are no any items loaded in RecyclerView then I have another solution for you.
In your layout.xml file, create <FrameLayout> and inside it, put the TextView showing message as "no objects" and also add RecyclerView in it. Also, in java file, in case of LOADED in overridden method, make visibility GONE for TextView. By thus, you can achieve it.
Correct friend, that's what I want to achieve. What I want to try to fix is that both methods are executed almost at the same time, when only 1 must be executed. But I will try to establish this method, in the method Loading_More
_Enviado desde mi Redmi Note 6 Pro usando FastHub_
Thank you very much friend, you saved my project.
@PatilShreyas thanks so much for helping @itzThiefz-exe !
Based on "you saved my project" sounds like I can close this issue.
Thank you very much friend, you saved my project.
Welcome! It's my pleasure!
Based on "you saved my project" sounds like I can close this issue.
Thank you!
Most helpful comment
Thank you very much friend, you saved my project.