1
私はこのJSONを持っている:表示テキストのAndroid
"result": [
{
"nama_p": "ACEH",
"IDProvinsi": "1"
},
{
"nama_p": "SUMATERA UTARA",
"IDProvinsi": "6728"
},
{
"nama_p": "SUMATERA BARAT",
"IDProvinsi": "12920"
}]
私は
.. BUイムは失敗..私は私のスピナーにnama_p表示するときIDProvinsi値を取得しようとしてきましたこれは私のJavaコードです:私はIDProvinsi上の値を取得し、私は2スピナーを持っている私の他のスピナー に送信しない方法
private void getData(){
//Creating a string request
StringRequest stringRequest = new StringRequest(Config.DATA_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
JSONObject j = null;
try {
//Parsing the fetched Json String to JSON Object
j = new JSONObject(response);
//Storing the Array of JSON String to our JSON Array
result = j.getJSONArray("result");
//Calling method getStudents to get the students from the JSON Array
getProv(result);
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
//Creating a request queue
RequestQueue requestQueue = Volley.newRequestQueue(this);
//Adding request to the queue
requestQueue.add(stringRequest);
}
private void getProv(JSONArray j){
//Traversing through all the items in the json array
for(int i=0;i<j.length();i++){
try {
//Getting json object
JSONObject json = j.getJSONObject(i);
//Adding the name of the student to array list
id.add(json.getString("IDProvinsi"));
provinsi.add(json.getString("nama_p"));
System.out.println(provinsi);
// MyClass[] obj ={
// new MyClass(provinsi,id)
// };
} catch (JSONException e) {
e.printStackTrace();
}
}
//Setting adapter to show the items in the spinner
spinnerprov.setAdapter(new ArrayAdapter<String>(AddLokasiActivity.this, android.R.layout.simple_spinner_dropdown_item,id));
}
ディスプレイ都市の表示状態のため 1. 2.
状態の値は私のWebサービスに送信するとき私は、スピナーを検索するために、私のスピナーを変更する必要があり
THXのstackoverflowの
ちょうどこの 'getProv(結果)後にアダプターを設定し、JSONの解析に問題がないように思える;'機能 –
私はnama_p ..を表示するまで問題はありませんが、スピナーが選んだときIDProvinsiを取得する方法は? –
スピナーのリスナーを使用して、あなたの位置を使用して、あなたの 'id'リストからデータを取得します –