Advertisement
Guest User

Untitled

a guest
Aug 28th, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1.         try
  2.             {
  3.                 JSONObject json = new JSONObject(result);
  4.                 JSONArray response = json.optJSONArray("response");
  5.  
  6.                 String[] tracks = new String[response.length()];
  7.  
  8.                 for(int i = 0; i < response.length(); i++)
  9.                 {
  10.                     JSONObject item = response.getJSONObject(i);
  11.  
  12.                     String artist = item.getString("artist");
  13.                     String title = item.getString("title");
  14.  
  15.                     tracks[i] = artist + " - " + title;
  16.  
  17.                 }
  18.  
  19.                 ListView lv = (ListView) findViewById(R.id.listView1);
  20.  
  21.                 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
  22.                         android.R.layout.simple_list_item_1, tracks);
  23.  
  24.                 lv.setAdapter(adapter);
  25.             }
  26.             catch (JSONException e)
  27.             {
  28.                 NotifyDialog(e.getMessage());
  29.             }
  30.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement