Compare text of items in a recyclerview

-1

I would like to know how to compare texts of items from a recyclerView in android.

And if the texts are equal , make the item text 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();


    }

Follow problem images.

In the above image, items 2 and 3 have the same name as item 1, so they would be invisible (GONE).

The image below shows how it should look.

    
asked by anonymous 20.03.2018 / 14:17

1 answer

0

== Tests the references of the two objects (if it is the same object in memory).

.equals() Tests whether the values of the objects are equal (if they are different objects in memory, but with the same values / contents).

So, use .equals() to compare.

Reference: link

    
21.03.2018 / 14:30