-1
I wonder how to compare text of items of a recyclerView on android.
And if the texts are the same, render the text of the entry below GONE.
public void pegarTexto (){
TextView um = (TextView) mRecyclerView.findViewHolderForItemId(mAdapter.getItemId(-1)).itemView.findViewById(R.id.nomePais);
TextView dois = (TextView) mRecyclerView.findViewHolderForItemId(mAdapter.getItemId(0)).itemView.findViewById(R.id.nomePais);
String pais1 = um.toString();
String pais2 = dois.toString();
if (pais1 == pais2){
dois.setVisibility(View.GONE);
mAdapter.notifyDataSetChanged();
}
Follows images of the problem.
In the image above items 2 and 3 have the same name as item 1, therefore they would be invisible (GONE).
In the image below I show how it should look.
In the onBindViewHolder method, make a comparison with the previous one, only do a treatment for when it is the first position. If it is equal you place the setVisibility of the item that has the text for GONE
– AndersonCanteiro
The doubt is really how to make this comparison, and how to infuse the previous item.
– Lázaro Rodrigues
if(position > 0){ if(mList.get(position - 1).equals(Holder.tvDate.gettext().toString().Trim()){ Holder.tvDate.setVisibility(View.GONE); } }
– AndersonCanteiro
I don’t know how you’re working, so I made an example with a string list
– AndersonCanteiro