查找具有给定ID的资源-作为变量 [英] Finding a resource given its ID - as a variable
本文介绍了查找具有给定ID的资源-作为变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果您知道ID,就很容易在布局中查找资源:
Finding a resource in your layout is easy if you know the id:
LinearLayout l = FindViewById<LinearLayout>(Resource.Id.linearLayout1);
但是说我有
String id = "linearLayout1";
如何访问资源ID并查找"正在寻找的ID?
How can I access the resource IDs and "find" the one I'm looking for?
推荐答案
You can use this: Resources#getIdentifier()
String id = "linearLayout1";
int resourceId = getResources().getIdentifier(id, "id", getPackageName());
我没有看到Xamarin标签.我不熟悉Xamarin,但据我所知,它模仿Android API,因此应该有类似的方法.
I didn't see the Xamarin tag. I am not familiar with Xamarin, but as far as I know, it mimics the Android API, so there should be a similar method available for that.
这篇关于查找具有给定ID的资源-作为变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文