Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- protected Void doInBackground(Void... arg0) {
- HttpHandler sh = new HttpHandler();
- // Making a request to url and getting response
- String url = "https://sfasys:sfa321@nfdapp.nabatigroup.com/sap/opu/odata/sap/ZPRJ_SD0003_SRV/SFASTOCKSet?$filter=Werks%20eq%20%27P174%27%20and%20Lgort%20eq%20%27GS00%27$";
- // String url = "http://api.androidhive.info/contacts/";
- String jsonStr = sh.makeServiceCall(url);
- Log.e(TAG, "Response from url: " + jsonStr);
- if (jsonStr != null) {
- try {
- JSONObject jsonObj = new JSONObject(jsonStr);
- // Getting JSON Array node
- JSONObject jso = jsonObj.getJSONObject("d");
- JSONArray contacts = jso.getJSONArray("results");
- // looping through All Contacts
- for (int i = 0; i < contacts.length(); i++) {
- JSONObject c = contacts.getJSONObject(i);
- String pcode = c.getString("Matnr");
- String stock = c.getString("Labst");
- // tmp hash map for single contact
- HashMap<String, String> contact = new HashMap<>();
- // adding each child node to HashMap key => value
- contact.put("pcode", pcode);
- contact.put("stock", stock);
- // adding contact to contact list
- contactList.add(contact);
- }
- } catch (final JSONException e) {
- Log.e(TAG, "Json parsing error: " + e.getMessage());
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- Toast.makeText(getApplicationContext(),
- "Json parsing error: " + e.getMessage(),
- Toast.LENGTH_LONG).show();
- }
- });
- }
- } else {
- Log.e(TAG, "Couldn't get json from server.");
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- Toast.makeText(getApplicationContext(),
- "Couldn't get json from server. Check LogCat for possible errors!",
- Toast.LENGTH_LONG).show();
- }
- });
- }
- return null;
- }
- @Override
- protected void onPostExecute(Void result) {
- super.onPostExecute(result);
- ListAdapter adapter = new SimpleAdapter(MainActivity.this, contactList,
- R.layout.list_item, new String[]{ "pcode","stock"},
- new int[]{R.id.pcode, R.id.stock});
- lv.setAdapter(adapter);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement