我有这个json:
"result": [
{
"nama_p": "ACEH",
"IDProvinsi": "1"
},
{
"nama_p": "SUMATERA UTARA",
"IDProvinsi": "6728"
},
{
"nama_p": "SUMATERA BARAT",
"IDProvinsi": "12920"
}]
当我在我的微调器上显示nama_p时,我一直在尝试获取IDProvinsi值。 我失败了..
这是我的java代码:
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));
}
如何获取IDProvinsi上的值并将其发送给我的其他微调器 我有2个微调器 1.用于显示状态 2.用于显示城市
我希望在州的价值发送到我的网络服务时显示城市
thx stackoverflow
答案 0 :(得分:0)
我已经改变了我的微调器以搜索微调器..它可以在这里看到它更有效
[Creating a text filter (like quick search) for a Spinner in Android