Android to find pictures by name

Source: Internet
Author: User

This is often the case in development: there are a number of similar images in the Drawable folder (the similarity here is not only similar to the image name, but also similar), and now you have to select one of them according to the user's operation. For example, in a speech-like development, press and hold the "talk" button can be entered into the user said, then, need to have a picture in real time to record the user speaking volume level (1 to 7), we can put 7 pictures in the Drawable folder, the name is "Voice1.png"-" Voice7.png ", use other code to get the current user speaking volume level, and then through level 1-7 to find the picture voice1.png-voice7.png. The code is as follows (the function in the code is only used to get the ID of the image, and the ID is assigned to ImageView afterwards):

1  Public int int Level ) {2         return context.getresources (). Getidentifier ("Voice" + Level, "drawable", Context.getpackagename ()); 3         // find a picture named voice in the Drawable folder of the package that contains the current context 4 }

Android to find pictures by name

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.