Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. private class ReadJSONFeedTask extends AsyncTask <String, Void, String>
  2. {
  3. protected String doInBackground(String...urls)
  4. {
  5. Log.d("JSON", "number of surveys in feed 3");
  6. return readJSONFeed(urls[0]);
  7. }
  8.  
  9. protected void onPostExecute(String result)
  10. {
  11. try{
  12. Log.d("JSON", "Result file - " + result);
  13. JSONArray jsonArray = new JSONArray(result);
  14.  
  15. for(int i=0; i<ksonArray.length(); i++)
  16. {
  17. Log.d("JSON", "result file - " + 1);
  18. JSONObject jsonObject3 = jsonArray.getJSONObject(i);
  19. Log.d("data json", jsonArray.getJSONObject(i).toString());
  20.  
  21. ab = new ArrayBook(jsonObject3.getString("book_id"), jsonObject3.getString("title"), jsonObject3.getString("author_code"));
  22. Toast.makeText(getBaseContext(), ab.getAuthor().toString(), Toast.LENGTH_SHORT).show();
  23. dataBook.add(ab);
  24. }
  25.  
  26. adapter = new CustomAdapter (getApplicationContext (), dataBook);
  27. lvi.setAdapter(adapter);
  28.  
  29. catch(Exception e)
  30. {
  31. e.printStackTrace();
  32. }
  33. }
  34. }
  35.  
  36. protected void onCreate(Bundle savedInstanceState){
  37. super.onCreate(savedInstanceState);
  38.  
  39. dataBook = new ArrayList<ArrayBook>();
  40.  
  41. setContentView(R.layout.activity_main);
  42. lvi = (ListView) findViewById(R.id.list);
  43.  
  44. Log.d("JSON", "number of surveys in feed");
  45. new ReadJSONFeedTask().execute("http://yustinuswidya.com/senghansun.json");
  46. Log.d("JSON", "number of surveys in feed 2");
  47.  
  48. adapter = new CustomAdapter(getApplicationContext(), dataBook);
  49. lvi.setAdapter(adapter);
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement