コード例 #1
0
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
   if (convertView == null)
     convertView = LayoutInflater.from(context).inflate(R.layout.row, parent, false);
   if (convertView != null) {
     try {
       ((TextView) convertView.findViewById(R.id.text1))
           .setText(jsonArray.getJSONObject(position).getString("trackName"));
       ((TextView) convertView.findViewById(R.id.text2))
           .setText(jsonArray.getJSONObject(position).getString("artistName"));
       String url = jsonArray.getJSONObject(position).getString("artworkUrl100");
       ImageView imageView = (ImageView) convertView.findViewById(R.id.image);
       if (cancelPotentialDownload(url, imageView)) {
         DownloadImageTask task = new DownloadImageTask(imageView, url);
         DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task);
         imageView.setImageDrawable(downloadedDrawable);
         if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) task.execute();
         else task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
       }
     } catch (JSONException e) {
       Log.e(Constants.LOG_TAG, "Bad JSON object from results array at " + position, e);
     }
   }
   return convertView;
 }