Issue
I have almost 1000 images with different categories like
- Students_Images_Folder
- Teachers_Images_Folder
- Parents_Images_Folder etc.
I want to keep import these images in my android project with categories not mdpi, xdpi,hdpi etc . Is there anyway to keep them categorized not merged in drawable.
Should I go for database ? I read that database is not suitable as it will lower efficiency. Any solution is welcomed. thanks for giving time to my silly question.
Solution
First of All you should add all images into drawable folder with unique name and of course some prefix like st for Student, tr for teacher and pr for parent.
Secondly you can create database with three tables to store the names of images into it individual category wise.
After that you can retrieve the images category wise from database and here is code to deal with resource id from file name.
OR
You can also create assets folder in android, here you can see how to create assets folder in android studio.
After creating assets folder you can create sub-directories according to your categories like student, teacher and parent.
And after than put images inside those directories.
Lastly load images from assets. To load images from sub-directories of assets implement following code
try
{
InputStream ims = getAssets().open("student/st_img.jpg");
Drawable d = Drawable.createFromStream(ims, null);
mImage.setImageDrawable(d);
ims .close();
}
catch(IOException ex)
{
return;
}
Answered By - sodhankit
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.