Guest User

Untitled

a guest
Nov 20th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity {
  2. String strJson = "https://plaza.one/api/status/";
  3. @Override
  4. protected void onCreate(Bundle savedInstanceState) {
  5. super.onCreate(savedInstanceState);
  6. setContentView(R.layout.activity_main);
  7. artist = findViewById(R.id.artist);
  8. title = findViewById(R.id.title);
  9. album = findViewById(R.id.album);
  10.  
  11. /************ JSON data ***********/
  12. RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
  13. JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(
  14. Request.Method.GET, strJson,
  15. null,
  16. new Response.Listener<JSONObject>() {
  17. @Override
  18. public void onResponse(JSONObject response) {
  19. try{
  20. JSONArray array = response.getJSONArray("playback");
  21. for(int i=0;i<array.length();i++){
  22. JSONObject student = array.getJSONObject(i);
  23. String artisti = student.getString("artist");
  24. String titlei = student.getString("title");
  25. String albumi = student.getString("album");
  26. artist.setText("Artist : "+artisti);
  27. title.setText("title : "+titlei);
  28. album.setText("album : "+albumi);
  29. }
  30. }catch (JSONException e){
  31. e.printStackTrace();
  32. }
  33. }
  34. },
  35. new Response.ErrorListener(){
  36. @Override
  37. public void onErrorResponse(VolleyError error){
  38. //Toast error
  39. }
  40. }
  41. );
  42.  
  43. requestQueue.add(jsonObjectRequest);
  44. }
  45.  
  46. }
Add Comment
Please, Sign In to add comment