问题描述
我有两个绘制的的苹果的和 如何在我的code得到绘制的名字,并比较他们与同样开始字母
社区编辑的问题
提问实际上是寻求两个问题 -
-
起初,他希望得到从ImageView的ID可绘制ID。 (THW绘制这在ImageView的显示)
-
然后,他希望从步骤1所获得绘制ID获得绘制名。
更新的答案
有关分1
有没有直接的方法。你需要通过 setTag在其中保存的ImageView
。那么你可以通过标签
可绘制的ID() getTag()
中的ImageView的。检索
步骤2
您应该
获取图像的名字 字符串imageName1 = context.getResources()getResourceEntryName(R.drawable.apple)。
//现在imageName1应该包含苹果。字符串imageName2 = context.getResources()getResourceEntryName(R.drawable.a)。
//现在imageName2应该包含A。如果(imageName1.toLowerCase()。的charAt(0)== imageName2.toLowerCase()。的charAt(0)){ //起始字符'A'是匹配}
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.
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
}
这篇关于如何从ImageView的Android中获得绘制对象名称并获得它的字符串名称比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!