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" that is a method that show an animation, but at this method I should pass a resource id; I tried with a string but it don't work, what can I do?
drawable for all drawable resources) and for each resource of that type, there is a static integer (for example, R. drawable. icon ). This integer is the resource ID that you can use to retrieve your resource.
A drawable resource is a common concept for a graphic that can be drawn to the screen and which one can retrieve with APIs such as getDrawable(int) or apply to another XML resource with attributes such as android:drawable and android:icon.06-Mar-2022.
For example, when you specify an ID to an XML resource using the plus sign — in the format android:id="@+id/myView" —it means that a new ID resource with the name “myView” needs to be created, and if it does not exist, create a unique integer for it and add to R. java .
Resource id - is an integer value. Just pass an int
:
private void translateRight(int resource){
ImageView img = (ImageView) findViewById(resource);
//stuff
}
Resource ID is an integer, not a String.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With