Back to project page cellar-communicator.
The source code is released under:
GNU General Public License
If you think the Android project cellar-communicator listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.vinit.orderplacer; /*from w w w .j a va 2s . c om*/ import java.util.ArrayList; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.params.BasicHttpParams; import org.apache.http.util.EntityUtils; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.app.ProgressDialog; import android.content.Context; import android.content.Intent; import android.os.AsyncTask; import android.widget.ArrayAdapter; import android.widget.Spinner; public class RetrieveSalesmen extends AsyncTask<Void, Void, String> { Context context; Spinner parties; String salesmanName; Intent i; ProgressDialog dialog; public RetrieveSalesmen(Context context, Spinner parties, String sname) { this.context = context; this.parties = parties; this.salesmanName = sname; dialog = new ProgressDialog(context); } @Override protected void onPreExecute() { dialog.setMessage("Loading"); dialog.show(); } @Override protected String doInBackground(Void... arg0) { String ret; IPGetter get_ip = new IPGetter(); HttpClient httpClient = new DefaultHttpClient(new BasicHttpParams()); HttpGet httpGet = new HttpGet(get_ip.getIP() + "parties.php"); try { HttpResponse httpResponse = httpClient.execute(httpGet); HttpEntity httpEntity = httpResponse.getEntity(); ret = EntityUtils.toString(httpEntity); } catch (Exception e) { e.printStackTrace(); ret = ""; } return ret; } @Override protected void onPostExecute(String result) { if(dialog.isShowing()) { dialog.dismiss(); } ArrayList<String> partyList = new ArrayList<String>(); JSONArray partyArr; JSONObject partyObj; try { partyArr = new JSONArray(result); for (int i = 0; i < partyArr.length(); i++) { partyObj = partyArr.getJSONObject(i); if (partyObj.getString("salesman").equals(salesmanName)) { partyList.add(partyObj.getString("party")); } } ArrayAdapter<String> party_adapter = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, partyList); parties.setAdapter(party_adapter); } catch (JSONException e) { e.printStackTrace(); } } }