Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my recyclerview their are countdown timer in each item..and when the first item countdown timer ends i want the item at the tom to go straight to bottom. The cycler should go on, till their are items in recylerview. I know how to add countdowntimer. Please let me know how to do the positioning logic Right image is what is required. eUEry — ImgBB[^]

What I have tried:

I know how to put timer and how to populate the recylerview..just help me in positiong the items
Posted
Comments
David Crow 17-Sep-21 8:14am    
"just help me in positiong the items"

Use the add() method of the list object that is associated with the adapter.
Kumar Harsh 2021 17-Sep-21 8:49am    
Can you please elabourate a bit..add() is giving me an infinte recylerview
David Crow 17-Sep-21 9:46am    
I'm assuming that all of the items being shown in the RecyclerView are contained in some sort of List object. For example, if item 0 needs to be moved to the end, do something like:
ItemInfo itemInfo = list.remove(0);
list.add(itemInfo);
adapter.notifyDataSetChanged();
Kumar Harsh 2021 17-Sep-21 10:06am    
Sir please Check this code..and let me know where to add the above 3 line which you told....


coursesArrayList = new ArrayList<>();
rcv.setHasFixedSize(false);
rcv.setItemViewCacheSize(4);
rcv.setLayoutManager(new LinearLayoutManager(getContext()));

// adding our array list to our recycler view adapter class.
myAdapter = new MyAdapter(coursesArrayList, this);

// setting adapter to our recycler view.
rcv.setAdapter(myAdapter);



// below line is use to get the data from Firebase Firestore.
// previously we were saving data on a reference of Courses
// now we will be getting the data from the same reference.
db.collection("categories").orderBy("categoryTime", Query.Direction.ASCENDING)
.addSnapshotListener(new EventListener<querysnapshot>() {
@Override
public void onEvent(@Nullable @org.jetbrains.annotations.Nullable QuerySnapshot value, @Nullable @org.jetbrains.annotations.Nullable FirebaseFirestoreException error) {
if (!value.isEmpty()) {
shimmerFrameLayout.stopShimmer();
shimmerFrameLayout.setVisibility(View.INVISIBLE);

List<documentsnapshot> list = value.getDocuments();

coursesArrayList.clear(); //clear old refresh new
for (DocumentSnapshot d : list) {
// after getting this list we are passing
// that list to our object class.
UserDet ud = d.toObject(UserDet.class);

assert ud != null;
ud.setCategoryID(d.getId());

// and we will pass this object class
// inside our arraylist which we have
// created for recycler view.
coursesArrayList.add(ud);

}
myAdapter.notifyDataSetChanged();
} else {
// if the snapshot is empty we are displaying a toast message.
Toast.makeText(getActivity() , "No data found in Database", Toast.LENGTH_SHORT).show();
}
}
});
David Crow 17-Sep-21 10:19am    
According to your "...when the first item countdown timer ends i want the item at the tom to go straight to bottom..." comment, you would add that code at the point where the item's timer is ending.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900