Android is dynamically set via parameters ImageView

Source: Internet
Author: User

I have such a scene in the course of my study. Like the weather forecast. I will parse the data according to the request, which is to change the weather icon according to the different daily or hourly

In this process, I think of the IF statement to judge, but I think this is unrealistic, too cumbersome. I found that the data I requested would probably have more than 30 icons, that is, if I use the IF statement to interpret

, I'm going to write 30 if .....

But I learned a way, I share to everyone to learn!!!!

Create Levellist.xml in the Drawable folder

Such as:

Set the src of Image view to a created XML file in Layout

Set in Java code

Imagetianqi_tv.getdrawable (). SetLevel (0);
This 0 represents the Evellist.xml.
Android:maxlevel= "0"

Android is dynamically set via parameters ImageView

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.