Reason analysis and solutions for accessing resource IDs in the Android library without using the Switch-case statement

Source: Internet
Author: User


The error is because the argument behind the case branch must be a constant, which means that the resource ID of the R.java in the library is not constant
public static final class animator {
public static int design_appbar_state_list_animator = 0x7f020001;
}
public static final class Array {
public static int card_tablist = 0x7f030001;
}
public static final class Attr {
public static int actionbardivider = 0x7f040001;
public static int actionbaritembackground = 0x7f040002;
public static int actionbarpopuptheme = 0x7f040003;
...}

As shown above, each resource ID is not declared final
The resource ID for the R.java under the project is as follows
public static final class animator {
public static final int design_appbar_state_list_animator=0x7f020000;
}
public static final class Array {
public static final int card_tablist=0x7f030000;
public static final int tab_list=0x7f030001;
}

Looked up a lot of information, except replace with If-else no other solution [Facepalm]

  

Reason analysis and solutions for accessing resource IDs in the Android library without using the Switch-case statement

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.