Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.tulpar.restapi.restapi;
- import android.app.Activity;
- import android.content.ClipData;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.ArrayAdapter;
- import android.widget.ImageView;
- import android.widget.TextView;
- import com.google.gson.Gson;
- import com.tulpar.restapi.restapi.models.Service;
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.util.List;
- /**
- * Created by tegar on 14/06/16.
- */
- public class ServiceAdapter extends ArrayAdapter<String> {
- private final Activity context;
- private final String[] name;
- private final String[] icon;
- private List<Service> service;
- private int sizes;
- Bitmap bitmap;
- public static final String ROOT_URL = "http://kece.id/";
- public ServiceAdapter(Activity context,int size , List<Service> services) {
- super(context, R.layout.content_main);
- this.context=context;
- this.name = new String[services.size()];
- this.icon = new String[services.size()];
- sizes = size;
- this.service = services;
- for (int i = 0; i < services.size(); i++) {
- name[i] = services.get(i).getName();
- icon[i] = services.get(i).getIcon();
- }
- Log.i("Tag", "Name data " + new Gson().toJson(services));
- Log.i("Tag", "Name data Name " + new Gson().toJson(name));
- }
- @Override
- public int getCount() {
- return service.size();
- }
- @Override
- public long getItemId(int position) {
- return position;
- }
- public View getView(int position,View view,ViewGroup parent) {
- LayoutInflater inflater=context.getLayoutInflater();
- View rowView=inflater.inflate(R.layout.content_main, null, true);
- Log.i("Tag", "Name data Size2 " + new Gson().toJson(position));
- sizes = position;
- for (int i = 0; i < sizes; i++) {
- name[i] = service.get(i).getName();
- icon[i] = service.get(i).getIcon();
- TextView name2 = (TextView) rowView.findViewById(R.id.name);
- ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
- URL url = null;
- try {
- url = new URL(new Gson().toJson(icon[i]));
- } catch (MalformedURLException e) {
- e.printStackTrace();
- }
- Bitmap bmp = null;
- try {
- bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
- } catch (IOException e) {
- e.printStackTrace();
- }
- imageView.setImageBitmap(bmp);
- String nama = new Gson().toJson(name[i]);
- name2.setText(nama);
- }
- Log.i("Tag", "Name data3 " + new Gson().toJson(name));
- return rowView;
- };
- }
Add Comment
Please, Sign In to add comment