Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. package com.retrofitjson.pharamjo.intent5122559;
  2.  
  3. import android.os.Bundle;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.support.v7.widget.LinearLayoutManager;
  6. import android.support.v7.widget.RecyclerView;
  7. import android.widget.TextView;
  8.  
  9. import com.android.volley.RequestQueue;
  10. import com.android.volley.Response;
  11. import com.android.volley.VolleyError;
  12. import com.android.volley.toolbox.JsonArrayRequest;
  13. import com.android.volley.toolbox.Volley;
  14.  
  15. import org.json.JSONArray;
  16. import org.json.JSONException;
  17. import org.json.JSONObject;
  18.  
  19. import java.util.ArrayList;
  20. import java.util.List;
  21.  
  22. /**
  23. * Created by PharamJo on 5/12/2559.
  24. */
  25.  
  26. public class Select extends AppCompatActivity {
  27.  
  28. private TextView show;
  29.  
  30. List<GetDataAdapter> GetDataAdapter1;
  31.  
  32. RecyclerView recyclerView;
  33.  
  34. RecyclerView.LayoutManager recyclerViewlayoutManager;
  35.  
  36. RecyclerView.Adapter recyclerViewadapter;
  37. int id_student=123;
  38. String GET_JSON_DATA_HTTP_URL = "http://pharamjo.96.lt/Select/ImageJsonData.php?";
  39.  
  40. String JSON_IMAGE_TITLE_NAME = "Id_student";
  41. String JSON_IMAGE_URL = "Url";
  42.  
  43.  
  44.  
  45. JsonArrayRequest jsonArrayRequest ;
  46.  
  47. RequestQueue requestQueue ;
  48.  
  49. @Override
  50. protected void onCreate(Bundle savedInstanceState) {
  51. super.onCreate(savedInstanceState);
  52. setContentView(R.layout.view);
  53.  
  54. GetDataAdapter1 = new ArrayList<>();
  55.  
  56. recyclerView = (RecyclerView) findViewById(R.id.recyclerview1);
  57.  
  58. recyclerView.setHasFixedSize(true);
  59.  
  60. recyclerViewlayoutManager = new LinearLayoutManager(this);
  61.  
  62. recyclerView.setLayoutManager(recyclerViewlayoutManager);
  63.  
  64. JSON_DATA_WEB_CALL();
  65.  
  66. show = (TextView)findViewById(R.id.show);
  67.  
  68.  
  69. /*Intent intent = getIntent();
  70. id_student = intent.getStringExtra("student");
  71. //show.setText(id_student);*/
  72.  
  73.  
  74. }
  75.  
  76.  
  77.  
  78. public void JSON_DATA_WEB_CALL(){
  79.  
  80. jsonArrayRequest = new JsonArrayRequest(GET_JSON_DATA_HTTP_URL + id_student ,
  81.  
  82.  
  83. new Response.Listener<JSONArray>() {
  84. @Override
  85. public void onResponse(JSONArray response) {
  86.  
  87. JSON_PARSE_DATA_AFTER_WEBCALL(response);
  88. }
  89. },
  90. new Response.ErrorListener() {
  91. @Override
  92. public void onErrorResponse(VolleyError error) {
  93.  
  94. }
  95. });
  96.  
  97. requestQueue = Volley.newRequestQueue(this);
  98.  
  99. requestQueue.add(jsonArrayRequest);
  100. }
  101.  
  102. public void JSON_PARSE_DATA_AFTER_WEBCALL(JSONArray array){
  103.  
  104. for(int i = 0; i<array.length(); i++) {
  105.  
  106. GetDataAdapter GetDataAdapter2 = new GetDataAdapter();
  107.  
  108. JSONObject json = null;
  109. try {
  110.  
  111. json = array.getJSONObject(i);
  112.  
  113. GetDataAdapter2.setImageTitleNamee(json.getString(JSON_IMAGE_TITLE_NAME));
  114.  
  115. GetDataAdapter2.setImageServerUrl(json.getString(JSON_IMAGE_URL));
  116.  
  117. } catch (JSONException e) {
  118.  
  119. e.printStackTrace();
  120. }
  121. GetDataAdapter1.add(GetDataAdapter2);
  122. }
  123.  
  124. recyclerViewadapter = new RecyclerViewAdapter(GetDataAdapter1, this);
  125.  
  126. recyclerView.setAdapter(recyclerViewadapter);
  127. }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement