Reputation: 345
I have seen several instances of this question on here and the provided solutions dont seem to work.
My goal : Update the background of my LinearLayout depending on what color i get back from a database query.
What I have so far:
if(teamc=="black"){
drawable = this.getResources().getDrawable(R.drawable.blackbackground);
Toast.makeText(TeamActivity.this,teamc, Toast.LENGTH_LONG).show();
teamColor.setBackgroundDrawable(drawable);
}
Team color is defined as
teamColor = (LinearLayout) findViewById(R.id.teamcolor);
What is happening is that the Toast is appearing just fine but the background is not changing.
Any help would be appreciated.
Upvotes: 1
Views: 6276
Reputation: 3485
In my application I use a WebView to display a web page, when the page is scale fits well but now are whites spaces on each side of the page, I can change the background to black color??
Upvotes: 0
Reputation: 11097
It is really strange if Toast is working but background is not changing.
Try using teamc.equals("black"){}
or
teamColor.setBackgroundResource(R.drawable.blackbackground);
Upvotes: 2
Reputation: 11211
Are you sure that that toast is showing and not other toast? Because you try to check a String
if it's equal to another String
by using == operator and that is wrong.
You have to use .equals()
method to make a comparison between two Objects.
Upvotes: 2
Reputation: 30855
call the invalidate() of the LinearLayout using teamColor object after set the background
teamColor.invalidate();
Upvotes: 0
Reputation: 928
try to make directly teamColor.setBackgroundResource(R.drawable.blackbackground);
Upvotes: 0