Skullaykutzz
Skullaykutzz

Reputation: 83

How can I put two different variables inside of a textview in recyclerview when it runs a second time?

I have one recyclierview adapter in my project. It loads two times and puts variables inside textview in activity. I want it to load different for the second time when it loads.

I just tried to make if clause for it. I wanted to make it will work else statement for first time adapter load. And I put "1" inside of i so, second time if i equals "1" it will work inside of if. But, when it loads the second time it is default value of i.

public class VoyageInformationAdapter extends RecyclerView.Adapter {
private String i;

                    if (i == "1"){
                        viewHolderBus.textV_from_city.setText(leg.getTo_city());
                        viewHolderBus.textV_to_city.setText(leg.getFrom_city());
                    }else{
                    viewHolderBus.textV_from_city.setText(leg.getFrom_city());
                    viewHolderBus.textV_to_city.setText(leg.getTo_city());
                    i = "1";
                   }}

How can I solve this problem?

Upvotes: 0

Views: 31

Answers (1)

Viswanath Kumar Sandu
Viswanath Kumar Sandu

Reputation: 2274

This code would work for you

public class VoyageInformationAdapter extends RecyclerView.Adapter {
private String i;

                    if (i != null && i.equals("1")){
                        viewHolderBus.textV_from_city.setText(leg.getTo_city());
                        viewHolderBus.textV_to_city.setText(leg.getFrom_city());
                    }else{
                    viewHolderBus.textV_from_city.setText(leg.getFrom_city());
                    viewHolderBus.textV_to_city.setText(leg.getTo_city());
                    i = "1";
                   }}

Upvotes: 3

Related Questions