我正在尝试开发一个Android应用程序,在注册期间,数据是从存储在资产文件夹中的Json中提取的,并将其填充在微调器中。在代码中,我有一个微调器和多个EditView和TextView。在注册中,用户从微调器中选择国家/地区,它应该自动将一些值设置为TextView或EditView,如国家/地区代码,国家/地区电话代码,id等,但我发现很难这样做,已经搜索过,但大多数人只有两个值,如id和name,而我的更多。代码正在修改,几周前我从这个网站的某个地方得到了它。
我把它添加到代码中
ArrayList<String> countryName = new ArrayList<String>();
ArrayList<String> phoneCode = new ArrayList<String>();
ArrayList<String> countryCode = new ArrayList<String>();
和这个
country = jObj.getString("name");
dial_code = jObj.getString("dial_code");
country_code = jObj.getString("code");
countryName.add(country);
phoneCode.add(dial_code);
countryCode.add(country_code);
TextCountry = (TextView) findViewById(R.id.country);
TextDialCode = (TextView) findViewById(R.id.dial_code);
TextCode = (TextView) findViewById(R.id.code);
json_string= loadJSONFromAsset();
ArrayList<String> countryName = new ArrayList<String>();
ArrayList<String> phoneCode = new ArrayList<String>();
ArrayList<String> countryCode = new ArrayList<String>();
{
try {
jsonObj =new JSONObject(json_string);
jsonArray =jsonObj.getJSONArray("countries");
String country, dial_code, country_code;
for (int i = 0; i < jsonArray.length(); i++){
JSONObject jObj = jsonArray.getJSONObject(i);
country = jObj.getString("name");
dial_code = jObj.getString("dial_code");
country_code = jObj.getString("code");
countryName.add(country);
phoneCode.add(dial_code);
countryCode.add(country_code);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
请我很高兴知道如何将名称设置为TextCountry,将代码设置为TextCode,并将dial_code设置为TextDialCode。
胡子哥哥
相关分类