Note that there are some explanatory texts on larger screens.

plurals
  1. PORelated Spinners
    primarykey
    data
    text
    <p>This application should have four or more related spinners which should reload when their 'parent' spinner' selection changes - as an example with 2 spinners: houses, and rooms - if you choose a house, the room spinner should reload from the sqlite database.</p> <p>I have tried two approaches: a MySpinner class that takes a "child" Spinner in its constructor and tells the child to update itself when OnSelectedItem is triggered, like so</p> <pre><code>public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int pos, long id) { if (MySpinner.this.mChild.equals(null) == false) { MySpinner.this.mChild.updateData((int)id); } } </code></pre> <p>the child's updateData is</p> <pre><code>public void updateData (int parentValue) { new backgroundTask().execute("create"); } </code></pre> <p>which background tasks is an AsyncTask to query the sqlite database:</p> <pre><code>@Override protected Void doInBackground(String... params) { Db = new MyDatabase(mContext); Db.open(); if(params[0] == "create") { if (mTable.equals("T_room")){ mCursor = mDb.getRooms(mParentValue); } } return null; } </code></pre> <p>My second approach has been to create all my spinners directly in the activity.java file. This second approach has me implement one AsyncTask for all 4 or more spinners and choose what to query from the db, based on who calls with what value.</p> <p>The first approach crashes on the only 'real' line of code in the asynctask, the second approach drives me mad with autosetting spinners and a jumble of ifs in the asynctask.</p> <p>I'm not a coder by any means, and wonder if someone well versed in object-oriented coding can enlighten me as to what would be good coding behaviour to solve my specific problem (several spinners that update each other on selection.)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload