Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. gridview.setAdapter(new ImageAdapter(getActivity(), responseList));
  2.  
  3. private void getImages(){
  4. String BASE_URL = IMAGES_URL + userDetails.getUID();
  5.  
  6.  
  7. JsonObjectRequest jsonObjReq = new JsonObjectRequest(
  8. Request.Method.GET,BASE_URL, null,
  9. new Response.Listener<JSONObject>() {
  10. @Override
  11. public void onResponse(JSONObject response) {
  12. try{
  13.  
  14.  
  15. JSONArray listArray = response.getJSONArray("images");
  16. images = new String[listArray.length()];
  17. for(int i = 0; i <= listArray.length();i++)
  18. {
  19. JSONObject row = listArray.getJSONObject(i);
  20.  
  21. String name = row.getString("image_url");
  22.  
  23. responseList.add(name);
  24.  
  25. Log.d(TAG, responseList.toString());
  26.  
  27. }
  28. gridview.setAdapter(new ImageAdapter(getActivity(), responseList));
  29.  
  30.  
  31. } catch (JSONException e)
  32. {
  33.  
  34. }
  35. }
  36. }, new Response.ErrorListener() {
  37. @Override
  38. public void onErrorResponse(VolleyError error) {
  39. Log.d(TAG, "Error: " + error.getMessage());
  40.  
  41.  
  42. }
  43. });
  44.  
  45. VolleyRequestQueue.getInstance(getActivity()).addToRequestQueue(jsonObjReq);
  46. }
  47.  
  48. package uk.co.ryanmoss.footballgroundguide_android;
  49.  
  50. /**
  51. * Created by ryanmoss on 28/03/2017.
  52. */
  53.  
  54. import android.content.Context;
  55. import android.util.Log;
  56. import android.view.View;
  57. import android.view.ViewGroup;
  58. import android.widget.BaseAdapter;
  59. import android.widget.GridView;
  60. import android.widget.ImageView;
  61.  
  62. import com.squareup.picasso.Picasso;
  63.  
  64. import java.util.ArrayList;
  65.  
  66. public class ImageAdapter extends BaseAdapter {
  67. private Context mContext;
  68. private ArrayList<String> imageUrls;
  69.  
  70.  
  71. public ImageAdapter(Context c, ArrayList<String> imageUrls) {
  72. mContext = c;
  73. this.imageUrls = imageUrls;
  74.  
  75.  
  76. }
  77.  
  78. public int getCount() {
  79. return imageUrls.size();
  80. }
  81.  
  82. public String getItem(int position) {
  83. return imageUrls.get(position);
  84. }
  85.  
  86. public long getItemId(int position) {
  87. return 0;
  88. }
  89.  
  90. // create a new ImageView for each item referenced by the Adapter
  91. public View getView(int position, View convertView, ViewGroup parent) {
  92. ImageView imageView;
  93. if (convertView == null) {
  94. // if it's not recycled, initialize some attributes
  95. imageView = new ImageView(mContext);
  96. imageView.setLayoutParams(new GridView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
  97. imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
  98. imageView.setPadding(8, 8, 8, 8);
  99. } else {
  100. imageView = (ImageView) convertView;
  101. }
  102.  
  103. Picasso picasso = Picasso.with(mContext);
  104. picasso.setIndicatorsEnabled(true);
  105. picasso.setLoggingEnabled(true);
  106.  
  107. String url = getItem(position);
  108.  
  109. Picasso
  110. .with(mContext)
  111. .load(getItem(position))
  112. .rotate(90f)
  113. .into(imageView);
  114. return imageView;
  115. }
  116.  
  117.  
  118.  
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement