There is such a JSON info{"id":"25","name":"Черновицкая область"} I parsed it and the region is inserted into autocomplettextview

  Log.d(TAG,"AutoComplete jsonArray"+ jsonArray); for(int i=0;i<jsonArray.length();i++){ JSONObject info = jsonArray.getJSONObject(i); Log.d(TAG,"AutoComplete info"+ info); String id=info.getString("id"); String name=info.getString("name"); list_name.add(name+id); } Log.d(TAG,"List"+ list_name); String[] region = list_name.toArray(new String[0]); String[] id = list_id.toArray(new String[0]); Log.d(TAG,"Array"+Arrays.toString(region)); ArrayAdapter<String> adapter = new ArrayAdapter<String>(AutoComplete.this, R.layout.autocompletephone,region); autoCompleteTextView.setAdapter(adapter); 

How to compare and send NOT area

 @Override protected Map<String, String> getParams() throws AuthFailureError { Map<String, String> parameters = new HashMap<String, String>(); parameters.put("region", autocompletextview.getText().toString()); 

and id depending on the selected area

 @Override protected Map<String, String> getParams() throws AuthFailureError { Map<String, String> parameters = new HashMap<String, String>(); parameters.put("id", ?????); 

    1 answer 1

    The ArrayAdapter class has a constructor that takes a List<T> , so here it is:

     String[] region = list_name.toArray(new String[0]); String[] id = list_id.toArray(new String[0]); 

    unnecessarily.

    After receiving the data, you can immediately place them in the HashMap (and it is best to immediately add them there):

     HashMap<String, String> regions = new HashMap<>(); for (int i=0; i<list_name.size(); i++) { regions.put(list_name.get(i), list_id.get(i)); } 

    Further, you can get the value by key:

     String id = regions.get(autocompletextview.getText().toString()); 

    And then process it.

    Ps. Note the code style: in Java, for naming variables, recommended lowerCamelCase.