Issue
I have a very simple problem
consider I'm retrieving a string value online using getText()
Method
Now depending upon value of string I have set my button background to red and blue.
If string value is red then button background is red and if it is blue then blue.
Now if I implement onClicklistener
to same button I would like to changes it's Background color. If it was Red then change it to blue and if it was blue then change it to red as long as user presses key.
mSolved = (Button) itemView.findViewById(R.id.book_solved);
mSolved.setText(g.getColorvalue());
if("Blue".equals(holder.mSolved.getText())){
mSolved.setBackgroundColor(BLUE);
}
if("Red".equals(holder.mSolved.getText())){
.mSolved.setBackgroundColor(RED);
}
mSolved.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(Background color is already BLue)
{
change to Red
}
else
{
Change to Blue
}
}
Solution
Try using FLAG variables. Something similar to this.
mSolved = (Button) itemView.findViewById(R.id.book_solved);
mSolved.setText(g.getColorvalue());
boolean IS_BLUE = false;
boolean IS_RED = false;
if("Blue".equals(holder.mSolved.getText())){
mSolved.setBackgroundColor(BLUE);
IS_BLUE = true;
}
if("Red".equals(holder.mSolved.getText())){
mSolved.setBackgroundColor(RED);
IS_RED = true;
}
mSolved.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(IS_BLUE)
{
mSolved.setBackgroundColor(RED);
IS_RED = true;
IS_BLUE = false;
}
else if(IS_RED)
{
mSolved.setBackgroundColor(BLUE);
IS_BLUE = true;
IS_RED = false;
}
}
Answered By - okcomputer_kid
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.