如何从Android片段中的string.xml链接字符串属性 [英] How to link a string property from string.xml in android fragment

查看:182
本文介绍了如何从Android片段中的string.xml链接字符串属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是android新手,可能无法链接字符串属性可能很奇怪.但我尝试谷歌,但没有运气.我有一个片段,需要使用在string.xml中定义的URL.但是我无法在片段类中链接它.有人可以帮我吗?!!!这是我在下面的尝试:

I am new to android and this may be odd that I can't link a string property. But I tried from google but no luck. I have a fragment where I need to use a URL which I have defined in string.xml. But I can't link it in my fragment class. Can anybody please help me on this please ?!!! Here are my attempts below :

我在string.xml文件中的属性>>>

My property in string.xml file >>>

<string name="url">http://ip/gaanbaajna/</string>

我要链接的Java代码(该类扩展了Fragment)>>>

My java code to link (the class extends Fragment) >>>

private String curURL = getString(R.string.url);

推荐答案

正确的方法

private String curURL = getActivity().getResources().getString(R.string.url);

这篇关于如何从Android片段中的string.xml链接字符串属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆