The database has a large multi-level list. In the application, I need to request a list of each level, depending on the selected parent level.

In the application, I created a Spinner into which the first level list is loaded, and I get the id of the "parent" selected in Spinner.

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); new AsyncRequest1().execute();//запрос, на получение списка и заполнение Spinner в нем mySpinner=(Spinner)findViewById(R.id.spinner); mySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { iing=(InventItemNumberGroup)mySpinner.getSelectedItem(); selectID=iing.getItemId();//получение id выбранного родителя для дальнейших загрузок "дочерних" элементов } @Override public void onNothingSelected(AdapterView<?> parent) { ... } }); } 

class AsyncRequest1 extends AsyncTask {

  @Override protected String doInBackground(String... arg) { ... } @Override protected void onPostExecute(String s) { super.onPostExecute(s); try{ ... myData=parser.list;//список для вывода в Spinner ArrayAdapter<InventItemNumberGroup> myAdapter = new ArrayAdapter<InventItemNumberGroup>(Second_activity.this, android.R.layout.simple_spinner_item, myData); mySpinner=(Spinner)findViewById(R.id.spinner); mySpinner.setAdapter(myAdapter);//заполнение Spinner'а } catch(Exception e){ ... } } } 

The logic of the application is as follows: in the first Spinner, a value is selected, a request to the database is made, the required "child list" is selected, a new Spinner is built, which is populated with this list, and which also has a setOnItemSelectedListener that tracks the selected value in this Spinner, and then the process is repeated until a "child" without "children" is reached.

I do not understand how to implement this process, with dynamic creation of Spinners on the form, sending and receiving data from the database and tracking the value selected in the Spinner created, to repeat the operation. It seems to me that you need to use recursion or a cycle, but I do not understand how to implement it. At all. Tell me, how can I implement the required operation?

    0