0
上午嘗試構建天氣應用程序使用凌空,我的代碼已經正常工作沒有任何問題。但我想添加語言到我的應用程序使用字符串,lang英語和阿拉伯語。我從wundgeound API獲取天氣信息。 wunground api包含許多語言。我試圖讓en和ar。使用字符串翻譯網址Android工作室
代碼
String url = "http://api.wunderground.com/api/xxxxxxxx/conditions/hourly/forecast10day/geolookup/"+R.string.lang+"https://stackoverflow.com/q/"+latitude+","+longitude+".json";
當我調試的URL
http://api.wunderground.com/api/xxxxx/conditions/hourly/forecast10day/geolookup/2131230829/q/33.2379217,44.3381602.json
我得到的數字,而不是語言AR或連接,最多可以得到
http://api.wunderground.com/api/xxxxx/conditions/hourly/forecast10day/geolookup/lang:AR or En/q/33.2379217,44.3381602.json
字符串資源的連接
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="about">About</string>
<string name="desc">weather</string>
<string name="forecast">weather forecast</string>
<string name="satellite">satellite</string>
<string name="news">news</string>
<string name="action_settings">setting</string>
<string name="app_name">weathery</string>
<string name="navigation_drawer_open">open</string>
<string name="navigation_drawer_close">close</string>
<string name="loading">please wait</string>
<string name="lang">lang:EN</string>
</resources>
阿拉伯語
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="about">عنا</string>
<string name="desc">مصدرك الاولى لمعرفة اخر اخبار الطقس و المناخ للعراق</string>
<string name="forecast">حالة الطقس</string>
<string name="satellite">الاقمار صناعية</string>
<string name="news">الاخبار</string>
<string name="action_settings">ضبط</string>
<string name="app_name">منظومة ارصاد العراق</string>
<string name="navigation_drawer_open">فتح</string>
<string name="navigation_drawer_close">غلق</string>
<string name="loading">يرجى الانتظار</string>
<string name="lang">lang:AR</string>
</resources>
'R.string.lang'是整數,而且只有string'的'ID。在使用它之前,你必須得到這個字符串。 –