简体   繁体   中英

Show multiple images in ImageView of Recycler View from drawable folder

I am reading data of employees from excel file stored in internal storage, unfortunately the app is totally offline and so have offline images , which i need to store in drawable folder.

Now the question i have is ; There are 350 images named as employee id , for example 1.jpg of emp id = 1 , 2.jpg of emp id = 2.

I am using RecyclerView , in that onBindViewHolder method i have to set images according to the employee id.

Please guide me to show the image into imageView. Please comment for more input from my side.

Plz dont mark it negative if you can't answer.

You could try something like this.

Example if trying to get employee 1526 the drawable would be R.drawable.1526

String id = employee.getId(); //1526
int imageId = context.getResources()
                     .getIdentifier(id, "drawable", context.getPackageName());

id being a string. then with the image view

imageView.setImageResource(imageId);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM