Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iterate through images

Tags:

java

android

I have 100 images, each is an image of a percentage, for example, 1%, 2%, 3%, etc.

What's the best way to go through each image? Should I add each image resource to a List or Dictionary(if that exists in Android). Or am I forced to hard code it?

public void ShowCircle(final int percentage){
    final ImageView ring = (ImageView)findViewById(R.id.ring);
    ring.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                for(int i = 0; i != percentage; i++)

                            //I was thinking here I can access list/dictionary records.
                ring.setImageResource(R.drawable.percent_1);
            }
        });
}
like image 494
Since_2008 Avatar asked Dec 06 '25 05:12

Since_2008


1 Answers

At OP's request, answering with a copypasta from a comment:

Have a look at How do I iterate through the id properties of R.java class? and Android: Programatically iterate through Resource ids.

...though this question should really just be closed as a dup.

like image 101
Matt Ball Avatar answered Dec 08 '25 17:12

Matt Ball