Back to project page android-javarx-example.
The source code is released under:
Apache License
If you think the Android project android-javarx-example listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.bnsantos.movies.adapter; /* w w w. jav a 2s .co m*/ import android.content.Context; import android.content.Intent; import android.net.Uri; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.TextView; import com.bnsantos.movies.R; import com.bnsantos.movies.model.Movie; import com.squareup.picasso.Picasso; /** * Created by bruno on 14/11/14. */ public class MovieAdapter extends ArrayAdapter<Movie> { public MovieAdapter(Context context, int resource) { super(context, resource); } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = LayoutInflater.from(getContext()).inflate(R.layout.adapter_movie, parent, false); TextView title = (TextView) convertView.findViewById(R.id.movieTitle); TextView score = (TextView) convertView.findViewById(R.id.movieScore); TextView rating = (TextView) convertView.findViewById(R.id.movieRating); ImageView poster = (ImageView) convertView.findViewById(R.id.moviePoster); convertView.setTag(new ViewHolder(title, score, rating, poster)); } ViewHolder viewHolder = (ViewHolder) convertView.getTag(); final Movie movie = getItem(position); viewHolder.title.setText(movie.getTitle()); viewHolder.rating.setText(getContext().getString(R.string.movie_rating, movie.getMpaa_rating())); viewHolder.score.setText(getContext().getString(R.string.movie_score, Integer.toString(movie.getRatings().getCritics_score()))); Picasso.with(getContext()).load(movie.getPosters().getDetailed()).fit().into(viewHolder.poster); viewHolder.poster.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(movie.getLinks().getAlternate())); getContext().startActivity(i); } }); return convertView; } private class ViewHolder { public final TextView title; public final TextView score; public final TextView rating; public final ImageView poster; private ViewHolder(TextView title, TextView score, TextView rating, ImageView poster) { this.title = title; this.score = score; this.rating = rating; this.poster = poster; } } }