If else condition in RecyclerView onBindViewHolder
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I'm trying to set up a if else statement on my onBindViewHolder()
such that it checks for status, then sets text and text color depending on the status found.
I've tried but it just gives me the results of the first condition on every item in the RecyclerView
.
Here is my code for the Adapter
:
public class PreviousSettingsAdapter extends RecyclerView.Adapter<PreviousSettingsAdapter.PreviousSettingsViewHolder> {
private List<Setting> SettingsModelList;
private Context context;
public PreviousSettingsAdapter(Context context, List<Setting> SettingsModelList) {
this.SettingsModelList = SettingsModelList;
this.context = context;
}
public class PreviousSettingsViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.date)
TextView date;
@BindView(R.id.Setting_id)
TextView SettingId;
@BindView(R.id.status)
TextView status;
public PreviousSettingsViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
}
@NonNull
@Override
public PreviousSettingsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.placed_Setting_items, parent, false);
return new PreviousSettingsViewHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull PreviousSettingsViewHolder holder, int position) {
Setting singleSetting = SettingsModelList.get(position);
holder.date.setText(singleSetting.getCreatedAt());
holder.SettingId.setText("Setting Id: " + String.valueOf(singleSetting.getId()));
boolean paymentStatus = singleSetting.getConfirmed();
boolean fulfilledStatus = singleSetting.getProcessed();
if (paymentStatus && !fulfilledStatus ) {
holder.status.setText(R.string.processed);
holder.status.getResources().getColor(R.color.colorOrange);
} else
if (!paymentStatus && !fulfilledStatus) {
holder.status.setText(R.string.unchanged);
holder.status.getResources().getColor(R.color.colorRed);
} else if(paymentStatus && fulfilledStatus){
holder.status.setText(R.string.delivered);
holder.status.getResources().getColor(R.color.colorGreen);
}else{
holder.status.setText(" ");
}
}
@Override
public int getItemCount () {
return SettingsModelList.size();
}
}
java

add a comment |
I'm trying to set up a if else statement on my onBindViewHolder()
such that it checks for status, then sets text and text color depending on the status found.
I've tried but it just gives me the results of the first condition on every item in the RecyclerView
.
Here is my code for the Adapter
:
public class PreviousSettingsAdapter extends RecyclerView.Adapter<PreviousSettingsAdapter.PreviousSettingsViewHolder> {
private List<Setting> SettingsModelList;
private Context context;
public PreviousSettingsAdapter(Context context, List<Setting> SettingsModelList) {
this.SettingsModelList = SettingsModelList;
this.context = context;
}
public class PreviousSettingsViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.date)
TextView date;
@BindView(R.id.Setting_id)
TextView SettingId;
@BindView(R.id.status)
TextView status;
public PreviousSettingsViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
}
@NonNull
@Override
public PreviousSettingsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.placed_Setting_items, parent, false);
return new PreviousSettingsViewHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull PreviousSettingsViewHolder holder, int position) {
Setting singleSetting = SettingsModelList.get(position);
holder.date.setText(singleSetting.getCreatedAt());
holder.SettingId.setText("Setting Id: " + String.valueOf(singleSetting.getId()));
boolean paymentStatus = singleSetting.getConfirmed();
boolean fulfilledStatus = singleSetting.getProcessed();
if (paymentStatus && !fulfilledStatus ) {
holder.status.setText(R.string.processed);
holder.status.getResources().getColor(R.color.colorOrange);
} else
if (!paymentStatus && !fulfilledStatus) {
holder.status.setText(R.string.unchanged);
holder.status.getResources().getColor(R.color.colorRed);
} else if(paymentStatus && fulfilledStatus){
holder.status.setText(R.string.delivered);
holder.status.getResources().getColor(R.color.colorGreen);
}else{
holder.status.setText(" ");
}
}
@Override
public int getItemCount () {
return SettingsModelList.size();
}
}
java

1
have u tried to print yout payment status and fulfilled status in the bind view holder? It might be logical error
– DemiDust
Jan 3 at 6:29
You want to changestatus
text color?
– Devendra Singh
Jan 3 at 8:52
holder.status.setTextColor(context.getResources.getColor(R.color.colorOrange));
set the color like this in your conditions. In your code you are not setting color.
– Devendra Singh
Jan 3 at 8:58
add a comment |
I'm trying to set up a if else statement on my onBindViewHolder()
such that it checks for status, then sets text and text color depending on the status found.
I've tried but it just gives me the results of the first condition on every item in the RecyclerView
.
Here is my code for the Adapter
:
public class PreviousSettingsAdapter extends RecyclerView.Adapter<PreviousSettingsAdapter.PreviousSettingsViewHolder> {
private List<Setting> SettingsModelList;
private Context context;
public PreviousSettingsAdapter(Context context, List<Setting> SettingsModelList) {
this.SettingsModelList = SettingsModelList;
this.context = context;
}
public class PreviousSettingsViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.date)
TextView date;
@BindView(R.id.Setting_id)
TextView SettingId;
@BindView(R.id.status)
TextView status;
public PreviousSettingsViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
}
@NonNull
@Override
public PreviousSettingsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.placed_Setting_items, parent, false);
return new PreviousSettingsViewHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull PreviousSettingsViewHolder holder, int position) {
Setting singleSetting = SettingsModelList.get(position);
holder.date.setText(singleSetting.getCreatedAt());
holder.SettingId.setText("Setting Id: " + String.valueOf(singleSetting.getId()));
boolean paymentStatus = singleSetting.getConfirmed();
boolean fulfilledStatus = singleSetting.getProcessed();
if (paymentStatus && !fulfilledStatus ) {
holder.status.setText(R.string.processed);
holder.status.getResources().getColor(R.color.colorOrange);
} else
if (!paymentStatus && !fulfilledStatus) {
holder.status.setText(R.string.unchanged);
holder.status.getResources().getColor(R.color.colorRed);
} else if(paymentStatus && fulfilledStatus){
holder.status.setText(R.string.delivered);
holder.status.getResources().getColor(R.color.colorGreen);
}else{
holder.status.setText(" ");
}
}
@Override
public int getItemCount () {
return SettingsModelList.size();
}
}
java

I'm trying to set up a if else statement on my onBindViewHolder()
such that it checks for status, then sets text and text color depending on the status found.
I've tried but it just gives me the results of the first condition on every item in the RecyclerView
.
Here is my code for the Adapter
:
public class PreviousSettingsAdapter extends RecyclerView.Adapter<PreviousSettingsAdapter.PreviousSettingsViewHolder> {
private List<Setting> SettingsModelList;
private Context context;
public PreviousSettingsAdapter(Context context, List<Setting> SettingsModelList) {
this.SettingsModelList = SettingsModelList;
this.context = context;
}
public class PreviousSettingsViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.date)
TextView date;
@BindView(R.id.Setting_id)
TextView SettingId;
@BindView(R.id.status)
TextView status;
public PreviousSettingsViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
}
@NonNull
@Override
public PreviousSettingsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.placed_Setting_items, parent, false);
return new PreviousSettingsViewHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull PreviousSettingsViewHolder holder, int position) {
Setting singleSetting = SettingsModelList.get(position);
holder.date.setText(singleSetting.getCreatedAt());
holder.SettingId.setText("Setting Id: " + String.valueOf(singleSetting.getId()));
boolean paymentStatus = singleSetting.getConfirmed();
boolean fulfilledStatus = singleSetting.getProcessed();
if (paymentStatus && !fulfilledStatus ) {
holder.status.setText(R.string.processed);
holder.status.getResources().getColor(R.color.colorOrange);
} else
if (!paymentStatus && !fulfilledStatus) {
holder.status.setText(R.string.unchanged);
holder.status.getResources().getColor(R.color.colorRed);
} else if(paymentStatus && fulfilledStatus){
holder.status.setText(R.string.delivered);
holder.status.getResources().getColor(R.color.colorGreen);
}else{
holder.status.setText(" ");
}
}
@Override
public int getItemCount () {
return SettingsModelList.size();
}
}
java

java

edited Jan 3 at 7:30
DawidJ
760717
760717
asked Jan 3 at 6:20
JayJay
136
136
1
have u tried to print yout payment status and fulfilled status in the bind view holder? It might be logical error
– DemiDust
Jan 3 at 6:29
You want to changestatus
text color?
– Devendra Singh
Jan 3 at 8:52
holder.status.setTextColor(context.getResources.getColor(R.color.colorOrange));
set the color like this in your conditions. In your code you are not setting color.
– Devendra Singh
Jan 3 at 8:58
add a comment |
1
have u tried to print yout payment status and fulfilled status in the bind view holder? It might be logical error
– DemiDust
Jan 3 at 6:29
You want to changestatus
text color?
– Devendra Singh
Jan 3 at 8:52
holder.status.setTextColor(context.getResources.getColor(R.color.colorOrange));
set the color like this in your conditions. In your code you are not setting color.
– Devendra Singh
Jan 3 at 8:58
1
1
have u tried to print yout payment status and fulfilled status in the bind view holder? It might be logical error
– DemiDust
Jan 3 at 6:29
have u tried to print yout payment status and fulfilled status in the bind view holder? It might be logical error
– DemiDust
Jan 3 at 6:29
You want to change
status
text color?– Devendra Singh
Jan 3 at 8:52
You want to change
status
text color?– Devendra Singh
Jan 3 at 8:52
holder.status.setTextColor(context.getResources.getColor(R.color.colorOrange));
set the color like this in your conditions. In your code you are not setting color.– Devendra Singh
Jan 3 at 8:58
holder.status.setTextColor(context.getResources.getColor(R.color.colorOrange));
set the color like this in your conditions. In your code you are not setting color.– Devendra Singh
Jan 3 at 8:58
add a comment |
1 Answer
1
active
oldest
votes
Debug and kindly see that the paymentStatus
and fulfilledStatus
values.As you said, it might be going into the if loop with those conditions satisfying.
Both status are evaluating to false yet that's not the case from the database
– Jay
Jan 3 at 10:10
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54017247%2fif-else-condition-in-recyclerview-onbindviewholder%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Debug and kindly see that the paymentStatus
and fulfilledStatus
values.As you said, it might be going into the if loop with those conditions satisfying.
Both status are evaluating to false yet that's not the case from the database
– Jay
Jan 3 at 10:10
add a comment |
Debug and kindly see that the paymentStatus
and fulfilledStatus
values.As you said, it might be going into the if loop with those conditions satisfying.
Both status are evaluating to false yet that's not the case from the database
– Jay
Jan 3 at 10:10
add a comment |
Debug and kindly see that the paymentStatus
and fulfilledStatus
values.As you said, it might be going into the if loop with those conditions satisfying.
Debug and kindly see that the paymentStatus
and fulfilledStatus
values.As you said, it might be going into the if loop with those conditions satisfying.
answered Jan 3 at 6:54
Meena DevMeena Dev
5719
5719
Both status are evaluating to false yet that's not the case from the database
– Jay
Jan 3 at 10:10
add a comment |
Both status are evaluating to false yet that's not the case from the database
– Jay
Jan 3 at 10:10
Both status are evaluating to false yet that's not the case from the database
– Jay
Jan 3 at 10:10
Both status are evaluating to false yet that's not the case from the database
– Jay
Jan 3 at 10:10
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54017247%2fif-else-condition-in-recyclerview-onbindviewholder%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
have u tried to print yout payment status and fulfilled status in the bind view holder? It might be logical error
– DemiDust
Jan 3 at 6:29
You want to change
status
text color?– Devendra Singh
Jan 3 at 8:52
holder.status.setTextColor(context.getResources.getColor(R.color.colorOrange));
set the color like this in your conditions. In your code you are not setting color.– Devendra Singh
Jan 3 at 8:58