Android: pass resource id as parameter

I have this code:

translateRight("iv1"); //iv1 is an id of an imageView

    private void translateRight(String st){

    ImageView img = (ImageView)findViewById(R.id.st);
        Animation a = AnimationUtils.loadAnimation(this, R.anim.translate_right);
        img.startAnimation(a);
    }

I have "translateRight", this is a method that shows the animation, but with this method I have to pass the resource identifier; I tried with a string, but this does not work, what can I do?

+5
source share
2 answers

Resource ID is an integer value. Just pass int:

private void translateRight(int resource){
    ImageView img = (ImageView) findViewById(resource);
    //stuff
}
+9
source

The resource identifier is an integer, not a string.

+5
source

All Articles