Easy Drawable

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Easy Drawable

Postby kdiddy » Fri Apr 03, 2009 2:44 am

Hi,

Is it possible to number drawables so they can be used depending on a variable defined in java?

For example

someimage.setBackgroundResource(R.drawable.lp1);

I want certain preferences to determine what drawables are used.

Like in this example, if I had some drawables name lp1, lp2, lp3, etc....could I call them with a variable when setting the background resource?

someimage.setBackgroundResource(R.drawable.lp[k]);

The above code won't work.

Any suggestions.

K
Diddy
kdiddy
Junior Developer
Junior Developer
 
Posts: 19
Joined: Wed Apr 01, 2009 2:30 am

Top

Postby rogerta » Fri Apr 03, 2009 2:07 pm

how about something like this:

int ids[] = { R.id.lp1, R.id.lp2, R.id.lp3 };

int i = // se to 0 to 2 depending on state
setBackground(ids[i]);
Roger
rogerta
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Apr 03, 2009 1:46 pm

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 5 guests