Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement