2014-12-20 2 views
0

I m trying to make a lisView with two textView and an imageView (that come as a url Sting) on each item at the list but, the list is not scrolling as good as I want, because its taking too long to load the image url. Im using an AsyncTask class for loading the the image but still it dosen t выглядеть так хорошо. вот мой код в ИНТ классе ArrayAdapter:Загрузка изображения в элемент ListView с использованием пейджинга, Android

public class MySimpleArrayAdapter extends ArrayAdapter<Movie> { 

final private Context context; 
final private Movie[] movies; 
ImageView movieIcon; 
TextView name, description; 
Bitmap bitmap; 

public MySimpleArrayAdapter(Context context, Movie[] movies) { 
    super(context,R.layout.item_in_movielist, movies); 
    this.context = context; 
    this.movies = movies; 
} 

@Override 
public View getView(final int position, View convertView, ViewGroup parent) { 


    LayoutInflater inflater = (LayoutInflater) context 
      .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View rowView = inflater.inflate(R.layout.item_in_movielist, parent, false); 


    name = (TextView) rowView.findViewById(R.id.tvMovieName); 
    description = (TextView) rowView.findViewById(R.id.tvMovieDescription); 
    movieIcon = (ImageView) rowView.findViewById(R.id.ivMovieIcon); 

    GetImageAsync getImageAsync = new GetImageAsync(); 
    getImageAsync.imageView = movieIcon; 

    name.setText(movies[position].getMovieName()); 
    description.setText(movies[position].getMovieDescription()); 

    getImageAsync.execute(position); 

    return rowView; 
} 

public class GetImageAsync extends AsyncTask<Integer, Void, Bitmap> { 
    public ImageView imageView; 
    @Override 
    protected void onPostExecute(Bitmap bitmap1) { 
     imageView.setImageBitmap(bitmap1); 
    } 

    @Override 
    protected Bitmap doInBackground(Integer... params) { 
     URL url = null; 
     try { 
      url = new URL(movies[params[0]].getMovieImgURL()); 
      HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 
      connection.setDoInput(true); 
      connection.connect(); 
      InputStream input = connection.getInputStream(); 
      return BitmapFactory.decodeStream(input); 

     } catch (MalformedURLException e) { 
      e.printStackTrace(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
     return null; 
    } 
} 

}

я понял, что это не способ сделать это, I`m ищет изменения моего кода в «пейджинг» и Я хочу сделать все правильно. любые подсказки, что я могу сделать?

P.S Если вы хотите показать мне, как добавить пейджинг для этого кода будет здорово.

Спасибо!

ответ

0
Picasso.with(mContext) 
      .load(img.get(pos).replaceAll(" ", "%20")) 
      .placeholder(R.drawable.ic_launcher) 
      .error(R.drawable.ic_launcher) 
      .noFade().resize(70, 70) 
      .into(v.image); 
+0

спасибо за быстрый повтор, должен ли я использовать его вместо класса AsynTask или внутри него? –

+0

Да использовать это вместо класса AsynTask –

Смежные вопросы