Advertisement
Guest User

Untitled

a guest
Jan 28th, 2015
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. package net.androidsensei.moviesensei;
  2.  
  3. import java.util.List;
  4. import android.app.Activity;
  5. import android.content.Context;
  6. import android.view.LayoutInflater;
  7. import android.view.View;
  8. import android.view.ViewGroup;
  9. import android.widget.BaseAdapter;
  10. import android.widget.ImageView;
  11. import android.widget.TextView;
  12. import com.squareup.picasso.Picasso;
  13.  
  14. public class MovieListAdapter extends BaseAdapter {
  15.  
  16. private Activity activity;
  17. private List<Movie> movies;
  18. private static LayoutInflater inflater=null;
  19.  
  20. public MovieListAdapter(Activity a, List<Movie> movies) {
  21. activity = a;
  22. this.movies = movies;
  23. inflater =
  24. (LayoutInflater)activity.getSystemService(
  25. Context.LAYOUT_INFLATER_SERVICE);
  26. }
  27.  
  28. public int getCount() {
  29. return movies.size();
  30. }
  31.  
  32. public Object getItem(int position) {
  33. return position;
  34. }
  35.  
  36. public long getItemId(int position) {
  37. return position;
  38. }
  39.  
  40. public View getView(int position, View convertView, ViewGroup parent) {
  41. View vi=convertView;
  42. ViewHolder holder;
  43. if(convertView==null){
  44. vi = inflater.inflate(R.layout.list_item, null);
  45. holder=new ViewHolder();
  46. holder.name = (TextView)vi.findViewById(R.id.name);
  47. holder.image = (ImageView)vi.findViewById(R.id.poster);
  48. vi.setTag(holder);
  49. }else{
  50. holder = (ViewHolder)vi.getTag();
  51. }
  52.  
  53. Movie item = new Movie();
  54. item = movies.get(position);
  55.  
  56. holder.name.setText(item.getName());
  57. Picasso.with(activity).load(item.getImage()).into(holder.image);
  58. return vi;
  59. }
  60.  
  61. public void setData(List<Movie> movies){
  62. this.movies.addAll(movies);
  63. this.notifyDataSetChanged();
  64. }
  65.  
  66. public class ViewHolder
  67. {
  68. TextView name;
  69. ImageView image;
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement