It may be a little complicated to access the file name, but there is a way to use setImageUri().
The format can be "android:resource//package/drawable/file name." If the package is "com.example.package" and the file name you want to recall is "premierlegue.png," write "android:resource//com.example.package/drawable/premierlegue.png."
Then, hand over the Uri object created using the setImageUri() method of the ImageView class.
Uri pathToImage = Uri.parse("android:resource//com.example.package/drawable/premierleague.png");
// Uri made in setImageUri().You can hand over the Uri object created through parse().
logoImageViews[i].setImageUri(pathToImage);
There's another way, but it's a little expensive, so you can experience lag if you use it in places like RecyclerView.
This is a method of using getResources().getIdentifier() in Activity, you can hand over the file name, resource type, and package when you call.
int imageResourceId = getResources().getIdentifier("premierleague.png", "drawable", getPacakageName());
// You can get the package name with getPacakageName() or you can write it yourself.
logoImageViews[i].setImageResource(imageResourceId);
© 2024 OneMinuteCode. All rights reserved.