Reputation: 83
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
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