Issue
I have two drawable apple and a how to get the drawable name in my code and compare that they starts with same alphabet
Community edited question
Questioner is actually seeking for 2 problems-
at first he wants to get the drawable id from the imageview id. (thw drawable which is showing in the imageview)
then he wants to get the drawable name from that obtained drawable id in step-1.
Solution
Updated answer
For step-1
There is no direct way. You need to save the drawable id in the imageview's Tag
via setTag()
. then you can retrieve by getTag()
of the imageview.
Step-2
you should get the image name by
String imageName1 = context.getResources().getResourceEntryName(R.drawable.apple);
// now imageName1 should contain "apple".
String imageName2 = context.getResources().getResourceEntryName(R.drawable.a);
// now imageName2 should contain "a".
if(imageName1.toLowerCase().charAt(0) == imageName2.toLowerCase().charAt(0))
{
// starting character 'a' is matching
}
Answered By - Amit K. Saha
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.