Я новичок в вызове Android API.Пожалуйста, помогите мне.Это метод, в котором я пытаюсь получить соответствующий идентификатор счетчика выбранного элемента.В методе get Doctors () я выбираю имя, а в методе Register Online мне нужно передать doc_id выбранного элемента счетчика в API
Call.
Как я могу получить идентификатор, выполнив это.
private void getData(String centerId) {
//Creating a string request
StringRequest stringRequest = new StringRequest(Request.Method.GET, Config.DATA_URL+centerId,
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(Config.JSON_ARRAY);
//Calling method getStudents to get the students from the JSON Array
getDoctors(result);
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
//Creating a request queue
RequestQueue requestQueue = Volley.newRequestQueue(getActivity());
//Adding request to the queue
requestQueue.add(stringRequest);
}
private void getDoctors(JSONArray j){ // Here in this method taking the spinner items
//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
docList.add(json.getString(Config.TAG_FIRST_NAME) + " " + json.getString(Config.TAG_LAST_NAME));
} catch (JSONException e) {
e.printStackTrace();
}
}
//Setting adapter to show the items in the spinner
doctorLists.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_dropdown_item, docList));
doctorLists.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { //Here I am trying to get the id of the spinner, but I am not getting how to get the id.
doc_id = docList.get(position);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
registerOnline(sharePreferenceManager.getUserLoginData(LoginModel.class).getResult().getCenterId(),
sharePreferenceManager.getUserLoginData(LoginModel.class).getResult().getTabID()
, ComponentUtils.getInputStringFromView(firstName)
, ComponentUtils.getInputStringFromView(lastName)
, gender
, ComponentUtils.getInputStringFromView(mobileNumber)
, ComponentUtils.getInputStringFromView(emailId)
, ComponentUtils.getInputStringFromView(adharNumber)
, ComponentUtils.getInputStringFromView(dateOfBirth)
, doc_id
, ComponentUtils.getInputStringFromView(referenceName)
, ComponentUtils.getInputStringFromView(messageBox));