Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. public class MySimpleArrayAdapter extends ArrayAdapter<Movie> {
  2.  
  3. final private Context context;
  4. final private Movie[] movies;
  5. ImageView movieIcon;
  6. TextView name, description;
  7. Bitmap bitmap;
  8.  
  9. public MySimpleArrayAdapter(Context context, Movie[] movies) {
  10. super(context,R.layout.item_in_movielist, movies);
  11. this.context = context;
  12. this.movies = movies;
  13. }
  14.  
  15. @Override
  16. public View getView(final int position, View convertView, ViewGroup parent) {
  17.  
  18.  
  19. LayoutInflater inflater = (LayoutInflater) context
  20. .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  21. View rowView = inflater.inflate(R.layout.item_in_movielist, parent, false);
  22.  
  23.  
  24. name = (TextView) rowView.findViewById(R.id.tvMovieName);
  25. description = (TextView) rowView.findViewById(R.id.tvMovieDescription);
  26. movieIcon = (ImageView) rowView.findViewById(R.id.ivMovieIcon);
  27.  
  28. GetImageAsync getImageAsync = new GetImageAsync();
  29. getImageAsync.imageView = movieIcon;
  30.  
  31. name.setText(movies[position].getMovieName());
  32. description.setText(movies[position].getMovieDescription());
  33.  
  34. getImageAsync.execute(position);
  35.  
  36. return rowView;
  37. }
  38.  
  39. public class GetImageAsync extends AsyncTask<Integer, Void, Bitmap> {
  40. public ImageView imageView;
  41. @Override
  42. protected void onPostExecute(Bitmap bitmap1) {
  43. imageView.setImageBitmap(bitmap1);
  44. }
  45.  
  46. @Override
  47. protected Bitmap doInBackground(Integer... params) {
  48. URL url = null;
  49. try {
  50. url = new URL(movies[params[0]].getMovieImgURL());
  51. HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  52. connection.setDoInput(true);
  53. connection.connect();
  54. InputStream input = connection.getInputStream();
  55. return BitmapFactory.decodeStream(input);
  56.  
  57. } catch (MalformedURLException e) {
  58. e.printStackTrace();
  59. } catch (IOException e) {
  60. e.printStackTrace();
  61. }
  62. return null;
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement