Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.asusx441n.examplelistviewdinamis;
- import android.app.ProgressDialog;
- import android.content.Context;
- import android.os.AsyncTask;
- import org.apache.http.NameValuePair;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- public class ServiceAll extends AsyncTask<String, String, ArrayList<HashMap<String, String>>> {
- Global global = new Global();
- private ProgressDialog pDialog;
- Context context;
- int success;
- String message;
- private JSONParser jsonParser = new JSONParser();
- JSONArray orders = null;
- ArrayList<HashMap<String, String>> isExist;
- public ServiceAll(Context context) {
- this.context = context;
- }
- @Override
- protected void onPreExecute() {
- super.onPreExecute();
- pDialog = new ProgressDialog(context);
- pDialog.setMessage("Add to database");
- pDialog.setIndeterminate(false);
- pDialog.setCancelable(true);
- //pDialog.show();
- }
- @Override
- protected ArrayList<HashMap<String, String>> doInBackground(String... params) {
- // Building Parameters
- List<NameValuePair> param = new ArrayList<NameValuePair>();
- JSONObject json = null;
- //param.add(new BasicNameValuePair("whattodo", params[0]));
- json = jsonParser.makeHttpRequest(global.URL_GET_CRUD, "POST", param);
- isExist = new ArrayList<HashMap<String, String>>();
- try {
- success = json.getInt(global.TAG_SUCCESS);
- message = json.getString(global.TAG_MESSAGE);
- if (success == 1) {
- // Getting Array of Return Value Login
- orders = json.getJSONArray("ceritarakyat");
- // looping through All Return Value
- for (int i = 0; i < orders.length(); i++) {
- JSONObject c = orders.getJSONObject(i);
- // Storing each json item in variable
- String id = c.getString(global.DATA_ID_STORY);
- String nik = c.getString(global.DATA_TITLE);
- String name = c.getString(global.DATA_PROVINSI);
- String note = c.getString(global.DATA_IMAGE1);
- String note2 = c.getString(global.DATA_IMAGE2);
- String content = c.getString(global.DATA_CONTENT);
- String autor = c.getString(global.DATA_AUTHOR);
- String outcame = c.getString(global.DATA_OUTCOME);
- // creating new HashMap
- HashMap<String, String> map = new HashMap<String, String>();
- // adding each child node to HashMap key => value
- map.put(global.DATA_ID_STORY, id);
- map.put(global.DATA_TITLE, nik);
- map.put(global.DATA_PROVINSI, name);
- map.put(global.DATA_IMAGE1, note);
- map.put(global.DATA_IMAGE2, note2);
- map.put(global.DATA_CONTENT, content);
- map.put(global.DATA_AUTHOR, autor);
- map.put(global.DATA_OUTCOME, outcame);
- // adding HashList to ArrayList
- isExist.add(map);
- }
- } else {
- return null;
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return isExist;
- }
- /**
- * After completing background task Dismiss the progress dialog
- **/
- protected void onPostExecute(ArrayList<HashMap<String, String>> file_url) {
- pDialog.dismiss();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement