나는안드로이드에서 국가 항목에 따라 텍스트를 설정하는 방법은 무엇입니까?
... 지금은 글고에서 스피너 항목에 따라 국가 코드를 설정하려면 ...하지만 난 스피너 항목에 따라 설정하는 방법을 알고 해달라고 회에서 국가 이름이 여기에 코드 (IS 무엇입니까 i)는 회 전자에서 국가 이름을 얻고있다 :
pmmobile = (EditText) findViewById(R.id.mob);
private void getCountryData(){
StringRequest stringRequest = new StringRequest(DATA_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
JSONObject j = null;
try {
Log.d("Test",response);
JSONArray result = new JSONArray(response);
//Calling method getCountry to get the Country from the JSON Array
getCountry(result);
} catch (JSONException e) {
e.printStackTrace();
}
}
},new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}});
RequestQueue requestQueue = Volley.newRequestQueue(this);
//Adding request to the queue
requestQueue.add(stringRequest);
}
private void getCountry(JSONArray jsonArrayCountry){
//Traversing through all the items in the json array
List<Country> countries = new ArrayList<>();
try {
String country_name, country_code;
JSONObject countries_object;
for (int i = 0; i < jsonArrayCountry.length(); i++) {
countries_object = jsonArrayCountry.getJSONObject(i);
country_code = countries_object.getString("id");
country_name = countries_object.getString("Name");
countries.add(new Country(country_code, country_name));
}
ArrayAdapter countryAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, countries);
pmcountry.setPrompt("Select Country");
pmcountry.setAdapter(countryAdapter);
pmcountry.setAdapter(new NothingSelectedSpinnerAdapter(countryAdapter,
R.layout.contact_spinner_row_nothing_selected,this));
pmcountry.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
} catch (JSONException e) {
Log.e("PMSearchActivity", e.getLocalizedMessage(), e);
}
}
내가 안드로이드 새로운, pmmobile..kindly 도움말에서 국가 코드를 설정합니다. 나는 당신이 String
을 표시하려는 경우 당신이 TextView
아닌 EditText
을 사용하려고한다고 가정
[
{
"id": "1",
"Name": "Afghanistan",
"CountryCode": "AF",
"CountryIso": "AFG"
},
{
"id": "2",
"Name": "Albania",
"CountryCode": "AL",
"CountryIso": "ALB"
},
실제로 휴대 전화 번호로 전화를 걸려면 국가 코드 대신 전화 코드로 변경하고 휴대 전화 번호를 추가합니다 – user7316606
http://stackoverflow.com/questions/42243097/how-to- make-linearlayout-design-in-android/42243434 # 42243434이 코드에서 호출 코드를 볼 수 있습니다. – user7316606