Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Hashmap for ListView
- ArrayList<HashMap<String, String>> all_itemList;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main_helloballi);
- all_itemList = new ArrayList<HashMap<String, String>>();
- // Calling async task to get json
- new getAllItem().execute();
- }
- private class getAllItem extends AsyncTask<Void, Void, Void> {
- @Override
- protected Void doInBackground(Void... arg0) {
- // Creating service handler class instance
- ServiceHandler sh = new ServiceHandler();
- // Making a request to url and getting response
- String jsonStr = sh.makeServiceCall(url, ServiceHandler.GET);
- Log.d("Response: ", "> " + jsonStr);
- if (jsonStr != null) {
- try {
- all_item = new JSONArray(jsonStr);
- // looping through All Contacts
- for (int i = 0; i < all_item.length(); i++) {
- JSONObject c = all_item.getJSONObject(i);
- String item_id = c.getString(TAG_ITEM_ID);
- String category_name = c.getString(TAG_CATEGORY_NAME);
- String item_name = c.getString(TAG_ITEM_NAME);
- // tmp hashmap for single contact
- HashMap<String, String> allItem = new HashMap<String, String>();
- // adding each child node to HashMap key => value
- allItem.put(TAG_ITEM_ID, item_id);
- allItem.put(TAG_CATEGORY_NAME, category_name);
- allItem.put(TAG_ITEM_NAME, item_name);
- // adding contact to contact list
- all_itemList.add(allItem);
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- } else {
- Log.e("ServiceHandler", "Couldn't get any data from the url");
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement