行继续在ListView

时间:2016-06-27 13:08:00

标签: android json image listview picasso

嗨,大家好我的Android应用程序有一个问题,它有一个自定义ListView与从Web服务器加载的图像,但图像不断重复,因为我向下滚动。我到处搜索,但没有任何对我有用。

public class MyListAdapter extends BaseAdapter{

protected JSONArray results;
protected Activity activity;
protected int layout;
protected Context context;
private static LayoutInflater inflater = null;

public MyListAdapter(JSONArray results, Activity activity, int layout, Context context){
    this.results = results;
    this.activity = activity;
    this.layout = layout;
    this.context = context;
    inflater = (LayoutInflater) this.activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return this.results.length();
}

@Override
public Object getItem(int position) {
    // TODO Auto-generated method stub
    return position;
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Cell cell;
    JSONObject object = null;
    try {
        object = this.results.getJSONObject(position);
    } catch (JSONException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    if(convertView == null){
        cell = new Cell();
        convertView = inflater.inflate(layout, null);
        cell.image = (ImageView) convertView.findViewById(R.id.image);
        cell.title = (TextView) convertView.findViewById(R.id.title);
        Typeface custom_font = Typeface.createFromAsset(context.getAssets(), "fonts/digital-7.ttf");
        cell.title.setTypeface(custom_font);
        try {
            cell.title.setText(object.getString("name"));
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            new DownloadImageTask(cell.image, object).execute("http://c2ez.ma/image.php?"+object.getString("id_product"));
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        convertView.setTag(cell);
    }else{
        cell = (Cell) convertView.getTag();
    }



    return convertView;
}

public String getUrl(int position) throws JSONException{
    JSONObject object = this.results.getJSONObject(position);
    return object.getString("url");
}

private static class Cell{
    protected TextView title;
    protected ImageView image;
}

private class DownloadImageTask extends AsyncTask<String, Void, String> {
      ImageView bmImage;
      JSONObject object;
      String imgUrl = null;

      public DownloadImageTask(ImageView bmImage, JSONObject object) {
          this.bmImage = bmImage;
          this.object = object;
      }



      @Override
    protected void onPreExecute() {
        bmImage.setImageResource(R.drawable.defaultimg);
    }

    protected String doInBackground(String... urls) {
        try {
            imgUrl = new Connector().GetImagePath("http://c2ez.ma/image.php?id="+object.getString("id_product"));
        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
          return imgUrl;
      }

      protected void onPostExecute(String result) {
          if(result == null){
              bmImage.setImageResource(R.drawable.defaultimg);
          }else{
              Picasso.with(context).cancelRequest(bmImage); 
              Picasso.with(context).load(result).tag(context).into(bmImage);
              bmImage.setTag(imgUrl);
          }
      }
    }

@Override
public int getItemViewType(int position) {
    // TODO Auto-generated method stub
    return super.getItemViewType(position);
}

@Override
public int getViewTypeCount() {
    // TODO Auto-generated method stub
    return super.getViewTypeCount();
}

}

我也尝试过移动代码,为if语句之外的视图赋值,我认为它有效,但是很长一段时间后就显示出来了。

编辑:当我看到我的logcat时,我发现当我向下滚动它需要花费很多时间才开始下载下一个图像并显示一条消息AsyncTask#5 calls()detach。

这是logcat: 当它显示网址时,表示它们已被下载。

06-27 13:09:38.821: I/System.out(10823): KnoxVpnUidStorageknoxVpnSupported API value returned is false
06-27 13:09:39.111: V/image(10823): http://c2ez.ma/img/p/2/4/24.jpg
06-27 13:09:39.131: W/Settings(10823): Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
06-27 13:09:39.151: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:09:39.361: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:39.361: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:09:39.371: V/image(10823): http://c2ez.ma/img/p/824-858.jpg
06-27 13:09:39.381: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:09:39.611: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:39.611: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:09:39.631: V/image(10823): http://c2ez.ma/img/p/1402-1428.jpg
06-27 13:09:39.651: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:09:39.861: I/System.out(10823): AsyncTask #2 calls detatch()
06-27 13:09:39.861: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:09:39.871: V/image(10823): http://c2ez.ma/img/p/1405-1431.jpg
06-27 13:09:39.931: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:09:40.111: I/System.out(10823): AsyncTask #2 calls detatch()
06-27 13:09:40.111: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:09:40.121: V/image(10823): http://c2ez.ma/img/p/1406-1432.jpg
06-27 13:09:40.121: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:09:40.361: I/System.out(10823): AsyncTask #2 calls detatch()
06-27 13:09:40.361: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:09:40.361: V/image(10823): http://c2ez.ma/img/p/1407-1433.jpg
06-27 13:09:40.381: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:09:40.591: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:40.591: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:09:40.591: V/image(10823): http://c2ez.ma/img/p/1408-1434.jpg
06-27 13:09:40.651: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:09:40.791: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:40.991: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:41.181: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:41.381: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:41.791: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:41.991: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:42.191: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:42.401: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:42.611: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:42.821: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:43.021: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:43.251: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:43.461: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:43.671: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:43.871: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:44.071: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:44.271: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:44.461: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:44.671: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:44.871: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:45.071: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:45.281: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:45.471: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:45.681: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:45.891: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:46.111: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:46.301: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:46.491: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:46.701: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:46.901: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:47.091: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:47.301: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:47.491: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:47.711: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:47.911: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:48.111: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:09:48.311: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:48.511: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:48.641: D/ViewRootImpl(10823): ViewPostImeInputStage ACTION_DOWN
06-27 13:09:48.711: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:48.951: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:49.151: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:49.351: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:49.551: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:49.601: D/ViewRootImpl(10823): ViewPostImeInputStage ACTION_DOWN
06-27 13:09:49.751: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:49.971: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:50.171: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:50.371: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:50.571: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:50.771: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:50.981: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:51.171: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:51.371: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:51.561: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:51.771: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:51.961: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:52.161: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:52.371: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:52.591: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:52.791: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:53.001: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:53.201: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:53.391: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:53.611: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:53.841: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:54.051: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:54.251: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:54.501: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:54.701: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:54.891: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:55.111: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:55.321: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:55.531: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:55.761: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:55.961: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:56.171: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:56.361: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:56.571: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:56.761: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:56.961: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:57.211: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:57.451: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:57.661: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:57.861: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:58.091: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:09:58.301: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:10:01.631: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:10:01.911: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:10:02.141: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:10:02.381: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:10:02.851: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:10:03.081: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:10:03.301: I/System.out(10823): AsyncTask #5 calls detatch()
06-27 13:10:03.511: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:03.711: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:03.921: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:04.131: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:04.351: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:04.551: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:04.761: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:04.991: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:05.201: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:05.391: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:05.601: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:05.801: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:06.011: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:06.221: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:06.421: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:06.641: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:06.851: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:07.051: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:07.251: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:07.451: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:07.661: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:07.911: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:08.111: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:08.311: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:08.511: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:08.711: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:08.961: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:09.241: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:09.241: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:10:09.251: V/image(10823): http://c2ez.ma/img/p/1409-1435.jpg
06-27 13:10:09.251: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:10:09.521: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:09.521: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:10:09.531: V/image(10823): http://c2ez.ma/img/p/1410-1436.jpg
06-27 13:10:09.551: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:10:09.801: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:09.801: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:10:09.821: V/image(10823): http://c2ez.ma/img/p/1411-1437.jpg
06-27 13:10:09.851: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:10:10.031: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:10.251: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:10.451: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:10.651: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:10.851: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:11.051: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:11.261: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:11.491: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:11.491: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:10:11.511: V/image(10823): http://c2ez.ma/img/p/1412-1438.jpg
06-27 13:10:11.521: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:10:11.771: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:11.771: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:10:11.781: V/image(10823): http://c2ez.ma/img/p/1413-1439.jpg
06-27 13:10:11.791: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:10:12.021: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:12.021: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:10:12.031: V/image(10823): http://c2ez.ma/img/p/1414-1440.jpg
06-27 13:10:12.061: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:10:12.241: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:12.451: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:12.651: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:12.871: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:13.071: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:13.271: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:13.481: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:13.691: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:14.891: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:15.101: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:15.301: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:15.521: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:15.721: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:15.921: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:16.171: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:16.171: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:10:16.181: V/image(10823): http://c2ez.ma/img/p/1415-1441.jpg
06-27 13:10:16.181: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:10:16.421: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:16.621: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:17.821: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:18.021: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:18.221: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:18.411: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:18.611: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:19.831: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:19.831: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:10:19.841: V/image(10823): http://c2ez.ma/img/p/1416-1442.jpg
06-27 13:10:19.841: I/System.out(10823): (HTTPLog)-Static: isSBSettingEnabled false
06-27 13:10:20.051: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:20.251: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:20.441: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:20.631: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:20.841: I/System.out(10823): AsyncTask #1 calls detatch()
06-27 13:10:21.041: I/System.out(10823): AsyncTask #1 calls detatch()

编辑:问题已经消失,但现在需要很长时间才能将图像加载到图像视图中大约30秒或更长时间,即使图像已下载。

2 个答案:

答案 0 :(得分:1)

您将age传递给cell.image。列表行视图被回收(多次使用相同的视图,您只填充行)。如果将引用传递给视图的一部分,则会向所有AsyncTasks添加相同的引用,并且在下载图像时,所有行都会一次填充。

建议:

  1. 使用DownloadImageTask的精确列表位置insead进行填充。
  2. 使用Picasso库,您对列表中的图片不会有任何问题。

答案 1 :(得分:0)

如下所示更改getView(),然后检查:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
Cell cell;
JSONObject object = null;
try {
    object = this.results.getJSONObject(position);
} catch (JSONException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
}

if(convertView == null){
    cell = new Cell();
    convertView = inflater.inflate(layout, null);
    cell.image = (ImageView) convertView.findViewById(R.id.image);
    cell.title = (TextView) convertView.findViewById(R.id.title);
    Typeface custom_font = Typeface.createFromAsset(context.getAssets(), "fonts/digital-7.ttf");
    cell.title.setTypeface(custom_font);
    try {
        cell.title.setText(object.getString("name"));
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    convertView.setTag(cell);
}else{
    cell = (Cell) convertView.getTag();
}



try {
  String imgUrl = "http://c2ez.ma/image.php?     id="+object.getString("id_product");
  Picasso.with(context).load(imgUrl).into(cell.image);
  cell.image.setTag(imgUrl);
  } catch (JSONException e) {
    // TODO Auto-generated catch block
      e.printStackTrace();
  }
    return convertView;
    }