I have a model class called (messages). In on bind view holder method of recycler view adapter I do this to extract the (time) string from the (messages) class:
@override
public void onBindViewHolder(final ViewHodler view holder, int position){
//here I extract the time value from (messages) class
messages mess=messageslist.get(position);
//I store it in a long variable called time
long time= mess.getTime();
}
Until here I am only getting the time value of each item in recycler view. But I want also to get the time of the previous item and compare it to the next one.
In other words I am trying to find the difference of time between each 2 items in recyclerview.
Thanks for your help.
EDIT
okay what I want to do is to show or hide a date view if the difference of date between the 2 items reached or passed 1 day. If I do it according to the answers below I get no results...like this
//the time of the item
long time= mess.getTime();
//the time of the previous item according to the answers below
long pre_time=messageslist.get(position-1).getTime();
//now I compare the difference
if(time - pre_time >= 24*3600*1000){
//show date
}else{
//hide date
}
but doest work.