tegarkurniawan

Adapter

Jun 13th, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. package com.tulpar.restapi.restapi;
  2.  
  3. import android.app.Activity;
  4. import android.graphics.Bitmap;
  5. import android.graphics.BitmapFactory;
  6. import android.util.Log;
  7. import android.view.LayoutInflater;
  8. import android.view.View;
  9. import android.view.ViewGroup;
  10. import android.widget.ArrayAdapter;
  11. import android.widget.ImageView;
  12. import android.widget.TextView;
  13.  
  14. import com.google.gson.Gson;
  15. import com.tulpar.restapi.restapi.models.Service;
  16.  
  17. import java.net.MalformedURLException;
  18. import java.net.URL;
  19. import java.util.List;
  20.  
  21. /**
  22. * Created by tegar on 14/06/16.
  23. */
  24. public class ServiceAdapter extends ArrayAdapter<String> {
  25.  
  26. private final Activity context;
  27. private final String[] name;
  28. private final String[] icon;
  29. private List<Service> service;
  30. Bitmap bitmap;
  31. public static final String ROOT_URL = "http://kece.id/";
  32.  
  33.  
  34. public ServiceAdapter(Activity context, List<Service> services) {
  35. super(context, R.layout.content_main);
  36. this.context=context;
  37. this.name = new String[services.size()];
  38. this.icon = new String[services.size()];
  39.  
  40. this.service = services;
  41. Log.i("Tag", "Name data " + new Gson().toJson(services));
  42. }
  43.  
  44. public View getView(int position,View view,ViewGroup parent) {
  45. LayoutInflater inflater=context.getLayoutInflater();
  46. View rowView=inflater.inflate(R.layout.content_main, null, true);
  47. Log.i("Tag", "Name data2 " + new Gson().toJson(service));
  48. for (int i = 0; i < service.size(); i++) {
  49.  
  50. name[i] = service.get(i).getName();
  51. icon[i] = service.get(i).getIcon();
  52. }
  53.  
  54. TextView name2 = (TextView) rowView.findViewById(R.id.name);
  55.  
  56.  
  57.  
  58.  
  59. Log.i("Tag", "Name data3 " + new Gson().toJson(name));
  60. name2.setText(new Gson().toJson(name));
  61.  
  62. return rowView;
  63.  
  64. };
  65. }
Advertisement
Add Comment
Please, Sign In to add comment