Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void getData(final String id) {
- final ProgressDialog loading = ProgressDialog.show(this, "Memuat Data", "Mohon Tunggu...", false, false);
- JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(DATA_URL,
- new Response.Listener<JSONArray>() {
- @Override
- public void onResponse(JSONArray response) {
- Log.d(TAG, response.toString());
- loading.dismiss();
- parseData(response);
- }
- },
- new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- loading.dismiss();
- }
- }) {
- protected Map<String, String> getParams() {
- Map<String, String> params = new HashMap<String, String>();
- params.put("id", id);
- return params;
- }
- };
- RequestQueue requestQueue = Volley.newRequestQueue(this);
- requestQueue.add(jsonArrayRequest);
- }
- private void parseData(JSONArray array) {
- for (int i = 0; i < array.length(); i++) {
- JSONObject json = null;
- try {
- json = array.getJSONObject(i);
- String Judul = json.getString(TAG_JUDUL);
- String Gambar = json.getString(TAG_IMAGE);
- String Bahan = json.getString(TAG_ISI);
- txt_judul.setText(Judul);
- txt_bahan.setText(Bahan);
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment