Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GetTime extends AsyncTask<Void, Void, Void> {
- public Context context;
- public GetTime(Context context) {
- this.context = context;
- }
- @Override
- protected void onPreExecute() {
- super.onPreExecute();
- }
- @Override
- protected Void doInBackground(Void... arg0) {
- HttpClient httpClient = new DefaultHttpClient();
- HttpPost httpPost = new HttpPost(urlTime);
- try {
- httpResponseTime = httpClient.execute(httpPost);
- StringHolderTime = EntityUtils.toString(httpResponseTime.getEntity(), "UTF-8");
- } catch (ClientProtocolException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- try {
- JSONArray jsonArray = new JSONArray(StringHolderTime);
- Log.i("MyLOG", "GetTime.doInBackground(): " + jsonArray.length());
- List<String> list = new ArrayList<String>();
- for (int i = 0; i < jsonArray.length(); i++) {
- JSONObject jsonObject = jsonArray.getJSONObject(i);
- String tim = jsonObject.getString("time");
- list.add(tim);
- }
- Log.i("MyLOG", "GetTime.doInBackground(): " + list);
- ArrayAdapter<String> adapter = new ArrayAdapter<String>(RecordActivity.this, android.R.layout.simple_spinner_item, list);
- adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- Spinner spinner = (Spinner) findViewById(R.id.spinner);
- spinner.setAdapter(adapter);
- } catch (JSONException e) {
- e.printStackTrace();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- protected void onPostExecute(Void result) {
- progressBar.setVisibility(View.GONE);
- }
- }
- public class GetTime extends AsyncTask<Void, Void, Void> {
- ArrayList<String> list;
- public Context context;
- public GetTime(Context context) {
- this.context = context;
- }
- @Override
- protected void onPreExecute() {
- super.onPreExecute();
- list=new ArrayList<>();
- }
- @Override
- protected Void doInBackground(Void... arg0) {
- HttpClient httpClient = new DefaultHttpClient();
- HttpPost httpPost = new HttpPost(urlTime);
- try {
- httpResponseTime = httpClient.execute(httpPost);
- StringHolderTime = EntityUtils.toString(httpResponseTime.getEntity(), "UTF-8");
- } catch (ClientProtocolException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- try {
- JSONArray jArray =new JSONArray(StringHolderTime);
- for(int i=0;i<jArray.length();i++){
- JSONObject jsonObject=jArray.getJSONObject(i);
- list.add(jsonObject.getString("time"));
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return null;
- }
- protected void onPostExecute(Void result) {
- listItems.addAll(list);
- sp=(Spinner)findViewById(R.id.spinner);
- adapter=new ArrayAdapter<String>(RecordActivity.this, android.R.layout.simple_spinner_dropdown_item, list);
- sp.setAdapter(adapter);
- progressBar.setVisibility(View.GONE);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement