user3026102
user3026102

Reputation: 1

changing he background image of the application

Hi I am beginner in android and I am trying to learn it, I wrote a small code for changing the background image of the application when clicking on some button:

public void processClicks(View display)
{
    display.setBackgroundResource(@drawable/fgd4);
}

but it got me an error message that : drawable cannot be resolved to a variable fgd4 cannot be resolved to a variable

but I have created a folder named drawable in the res folder and I put the fgd4.jpg image in it.

Please help me to solve this small problem

Upvotes: 0

Views: 48

Answers (2)

dm78
dm78

Reputation: 1600

You must reference your drawable in code differently than you do in your XML layouts.

display.setBackgroundResource( R.drawable.fgd4 );

Upvotes: 1

Subramanian Ramsundaram
Subramanian Ramsundaram

Reputation: 1347

Try Like This:

display.setBackgroundResource(R.drawable.fgd4);

Upvotes: 0

Related Questions