Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I see a couple of solutions here:</p> <h2>Option 1:</h2> <p>Instead of declaring <code>stateList</code> as an <code>ArrayList&lt;String&gt;</code>, create a custom POJO <code>StateInfo</code> and designate stateList as <code>ArrayList&lt;StateInfo&gt;</code></p> <pre><code>public class StateList { private int id; private String stateName; //Constructors, getters and setters } </code></pre> <p>Then, </p> <pre><code>if(! stateCursor.isAfterLast()){ do{ int id = stateCursor.getInt(0); String stateName = stateCursor.getString(1); stateList.add(new StateInfo(id, stateName)); }while(stateCursor.moveToNext()); } </code></pre> <p>Now, you can do this:</p> <pre><code>public void onItemSelected(AdapterView&lt;?&gt; parent, View v, int pos, long id) { int id = stateList.get(pos).getId(); //Use This ID to construct your next SQLite query; and populate the district spinner. } </code></pre> <p>If you do this, you will have to create a custom <code>ArrayAdapter</code> and implement the <code>getView()</code> method. Look at the Android docs for how to do this.</p> <h2>Option 2:</h2> <p>Why do you even need the stateID? I suppose you can write a Query to get the districts list given a state Name only. In that case, you can retain the <code>stateList</code> as an <code>ArrayList&lt;String&gt;</code> and you don't even need the <code>StateInfo</code> class at all. Just do this:</p> <pre><code>public void onItemSelected(AdapterView&lt;?&gt; parent, View v, int pos, long id) { String stateName = stateList.get(pos); //Use this name to construct your next SQLite query; and populate the district spinner. } </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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