Android Open Source - Post List Adapter

From Project

Back to project page


The source code is released under:

Copyright (c) 2013 Karl Monaghan ( Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Soft...

If you think the Android project listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*from  w  w  w . j av  a 2s  .  c  o m*/
import android.content.Context;
import android.text.Html;
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.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

public class PostListAdapter extends ArrayAdapter<Post> {
    // private static final String TAG = "PostListAdapter";

    public static class ViewHolder {
        public TextView titleView;

        public TextView dateView;

        public TextView commentCountView;

        public ImageView featuredImage;

    public PostListAdapter(Context context) {
        super(context, R.layout.activity_post_list);

    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;

        ViewHolder holder;
        Activity activity = (Activity) getContext();
        if (v == null) {
            LayoutInflater vi = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.post_list_item, null);
            holder = new ViewHolder();
            holder.titleView = (TextView) v.findViewById(;
            holder.dateView = (TextView) v.findViewById(;
            holder.commentCountView = (TextView) v.findViewById(;
            holder.featuredImage = (ImageView) v.findViewById(;
        } else {
            holder = (ViewHolder) v.getTag();

        final Post post = getItem(position);
        if (post != null) {


            String featuredImage = post.getFeaturedImage();

            if ((featuredImage != null) && (featuredImage.length() > 0)) {
                DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory().cacheOnDisc()
                 * .displayer( new RoundedBitmapDisplayer(activity.getResources().getDimensionPixelSize(
                 * R.dimen.standard_corner_radius)))
                ImageLoader.getInstance().displayImage(featuredImage, holder.featuredImage, options);


        return v;

Java Source Code List