Note that there are some explanatory texts on larger screens.

plurals
  1. POpopulate two spinners from mysql database that are dependant to each other
    primarykey
    data
    text
    <p>i have 2 spinners one for Province and other for City and if i select Gauteng in Province spinner the second spinner must show Johannesburg,Pretoria,Centurion and if i select KZN in province i want the second spinner to show Petermaritsburg,Durban,Ulundi</p> <p>Here is my code that i have tried to use but is not working at all.i will appriciate your help</p> <pre><code>int ct_id; String[] ct_name = null; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.extras); provins = (Spinner) findViewById(R.id.spinprovince); city = (Spinner) findViewById(R.id.spincity); save = (Button) findViewById(R.id.btnsave); String result = null; InputStream is = null; StringBuilder sb = null; // http post try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://10.0.2.2/php/ttz.php"); // httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = entity.getContent(); } catch (Exception e) { Log.e("log_tag", "Error in http connection" + e.toString()); } // convert response to string try { BufferedReader reader = new BufferedReader(new InputStreamReader( is, "iso-8859-1"), 8); sb = new StringBuilder(); sb.append(reader.readLine() + "\n"); String line = "0"; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); result = sb.toString(); } catch (Exception e) { Log.e("log_tag", "Error converting result " + e.toString()); } // paring data JSONArray jArray; try { jArray = new JSONArray(result); JSONObject json_data = null; ct_name = new String[jArray.length()]; for (int i = 0; i &lt; jArray.length(); i++) { json_data = jArray.getJSONObject(i); ct_id = json_data.getInt("idprovince"); ct_name[i] = json_data.getString("provincename"); ArrayAdapter aa = new ArrayAdapter(this,android.R.layout.simple_spinner_item,ct_name); aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); provins.setAdapter(aa); } } catch (JSONException e1) { Toast.makeText(getBaseContext(), "No City Found", Toast.LENGTH_LONG) .show(); } catch (ParseException e1) { e1.printStackTrace(); } } } </code></pre>
    singulars
    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.
 

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