Set the value of the hidden field with the corresponding data of the element selected from AutoCompleteTextView

I have an AutoCompleteTextView that offers the name of a place stored in a MySQL database by calling api when changing text using onTextChanged . The answer is a JSON array with many elements like place_name, id, location_key, query_type, request_type, etc. (Each with its own purpose). I have 3 hidden EditText fields. On setOnItemClickListener , when the user selects a place name, I want these 3 hidden fields to automatically set their value using location_key, query_type and request_type, since I need to send these 3 values โ€‹โ€‹with a place name in order to get the desired result from api.

+5
source share
2 answers

As soon as you click on the place_name field, hidden EditTexts should get the values โ€‹โ€‹needed to send to the database. This can be easily obtained by following these steps:

 textMessage.addTextChangedListener(new TextWatcher(){ public void afterTextChanged(Editable s) { if (textMessage == "//Name of place") { editText1.setText "//whatever you need"; editText2.setText "//whatever you need"; editText3.setText "//whatever you need"; } } }); 

Alternatively, I would use a spinner to name the place and encode it with something similar to this:

@Override public void onClick (Show arg0) {

  int range = spnDonate.getSelectedItemPosition(); Donator_Name = tboxName.getText().toString(); switch(range) { case 0: editText1.setText = "//whatever you need"; editText2.setText = "//whatever you need"; editText3.setText = "//whatever you need"; break; case 1: editText1.setText = "//whatever you need"; editText2.setText = "//whatever you need"; editText3.setText = "//whatever you need"; break; case 2: editText1.setText = "//whatever you need"; editText2.setText = "//whatever you need"; editText3.setText = "//whatever you need"; break; } } 

Hope this helps :)

0
source

Set the visibility of these fields.

  txtview.setVisibility(View.GONE); 

and when you want to make them visible, use

  txtPromo.setVisibility(View.VISIBLE); 
-1
source

Source: https://habr.com/ru/post/1203124/


All Articles