本文介绍了如何从ImageView的Andr​​oid中获得绘制对象名称并获得它的字符串名称比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个绘制的苹果 如何在我的code得到绘制的名​​字,并比较他们与同样开始字母

社区编辑的问题

提问实际上是寻求两个问题 -


  1. 起初,他希望得到从ImageView的ID可绘制ID。 (THW绘制这在ImageView的显示)


  2. 然后,他希望从步骤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-

  1. at first he wants to get the drawable id from the imageview id. (thw drawable which is showing in the imageview)

  2. 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的Andr​​oid中获得绘制对象名称并获得它的字符串名称比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 00:52