So so:
if (condition 1) { image.setbackground (r.id.xxx1); Else if (condition 2) { image.setbackground (r.id.xxx2);
As a matter of fact. If you have more states, you should create a new XML under the Drawable folder:
<level-listxmlns:android= "Http://schemas.android.com/apk/res/android"> <ItemAndroid:maxlevel= "4"android:drawable= "@drawable/stat_sys_battery_0" /> <ItemAndroid:maxlevel= "+"android:drawable= "@drawable/stat_sys_battery_10" /> <ItemAndroid:maxlevel= "$"android:drawable= "@drawable/stat_sys_battery_20" /> <ItemAndroid:maxlevel= "$"android:drawable= "@drawable/stat_sys_battery_40" /> <ItemAndroid:maxlevel= " the"android:drawable= "@drawable/stat_sys_battery_60" /> <ItemAndroid:maxlevel= "The "android:drawable= "@drawable/stat_sys_battery_80" /> <ItemAndroid:maxlevel= "+"android:drawable= "@drawable/stat_sys_battery_100" /> </level-list>
When you transform a picture in a program, you only need to use:
Imageview.getdrawable (). SetLevel (50);
Android automatically selects the corresponding image based on the level value. The phone shows the remaining charge is the way to display different pictures.
Different images in the same imageview in Android based on status