Skip to content

Instantly share code, notes, and snippets.

@mancdevcarl
Last active December 17, 2015 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mancdevcarl/5654121 to your computer and use it in GitHub Desktop.
Save mancdevcarl/5654121 to your computer and use it in GitHub Desktop.
Custom Listview Example
public class ListViewAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<VideoObject> data;
private static LayoutInflater inflater = null;
public ImageLoader imageLoader;
Context cx;
public ListViewAdapter(Activity a, ArrayList<VideoObject> videoObjListParam) {
activity = a;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader = new ImageLoader(activity.getApplicationContext());
data = videoObjListParam;
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
if (convertView == null)
vi = inflater.inflate(R.layout.list_row, null);
ImageView thumbImage = (ImageView) vi.findViewById(R.id.image);
TextView title = (TextView) vi.findViewById(R.id.title);
title.setText(data.get(position).getTitle());
TextView author = (TextView) vi.findViewById(R.id.author);
author.setText(data.get(position).getAuthor());
TextView year = (TextView) vi.findViewById(R.id.year);
year.setText(String.valueOf(data.get(position).getYear()));
TextView quality = (TextView) vi.findViewById(R.id.quality);
quality.setText(data.get(position).getQuality() + " Q");
TextView duration = (TextView) vi.findViewById(R.id.duration);
duration.setText(data.get(position).getDuration() + " min");
imageLoader.DisplayImage(data.get(position).getThumbnailUrl(),
thumbImage);
return vi;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment