Android Open Source - OpenCmsMobile-AndroidApp News Adapter






From Project

Back to project page OpenCmsMobile-AndroidApp.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project OpenCmsMobile-AndroidApp 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

package cz.nelasoft.opencms.mobile;
//from   w  w  w .ja va  2  s  .  c o  m
import java.util.List;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class NewsAdapter extends ArrayAdapter<News> {

  private final LayoutInflater mInflater;

  private List<News> data;

  private Context context;

  // private DrawableBackgroundDownloader dbd = new
  // DrawableBackgroundDownloader();

  private ImageLoader imageLoader;

  public NewsAdapter(Context context) {
    super(context, android.R.layout.simple_list_item_2);
    mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    this.context = context;
    imageLoader = new ImageLoader(context, R.drawable.z_file_png);
  }

  public void setData(List<News> data) {
    this.data = data;
    clear();
    if (data != null) {
      for (News appEntry : data) {
        add(appEntry);
      }
    }
  }

  public List<News> getData() {
    return data;
  }

  /**
   * Populate new items in the list.
   */
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    View view = null;

    if (convertView == null) {
      view = mInflater.inflate(R.layout.list_item_news, parent, false);
    } else {
      view = convertView;
    }

    News item = getItem(position);
    /**
     * if (item.getBitmap() != null) {
     * ((ImageView)view.findViewById(R.id.newsImage
     * )).setImageBitmap(item.getBitmap()); } else {
     * ((ImageView)view.findViewById
     * (R.id.newsImage)).setImageResource(R.drawable.z_file_png); }
     */

    if (!TextUtils.isEmpty(item.getImagePath())) {
      imageLoader.displayImage(Config.getConfigContext() + item.getImagePath(), (ImageView) view.findViewById(R.id.newsImage));
    }
    // dbd.loadDrawable(Config.getConfigContext() + item.getImagePath(),
    // (ImageView)view.findViewById(R.id.newsImage), null);

    ((TextView) view.findViewById(R.id.newsHeadline)).setText(item.getHeadline());
    // ((TextView)view.findViewById(R.id.newsPerex)).setText(item.getPerex());

    if (item.getDate() != null) {
      java.text.DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(context);
      String dateValue = dateFormat.format(item.getDate());

      ((TextView) view.findViewById(R.id.newsDate)).setText(dateValue);
    }
    return view;
  }

}




Java Source Code List

cz.nelasoft.opencms.mobile.Config.java
cz.nelasoft.opencms.mobile.ContactsFragment.java
cz.nelasoft.opencms.mobile.DownloadManager.java
cz.nelasoft.opencms.mobile.EventAdapter.java
cz.nelasoft.opencms.mobile.EventDetailActivity.java
cz.nelasoft.opencms.mobile.EventFragment.java
cz.nelasoft.opencms.mobile.Event.java
cz.nelasoft.opencms.mobile.FileCache.java
cz.nelasoft.opencms.mobile.IRefreshFragment.java
cz.nelasoft.opencms.mobile.ImageLoader.java
cz.nelasoft.opencms.mobile.MainActivity.java
cz.nelasoft.opencms.mobile.MemoryCache.java
cz.nelasoft.opencms.mobile.NewsAdapter.java
cz.nelasoft.opencms.mobile.NewsDetailActivity.java
cz.nelasoft.opencms.mobile.NewsFragment.java
cz.nelasoft.opencms.mobile.News.java
cz.nelasoft.opencms.mobile.SplashActivity.java
cz.nelasoft.opencms.mobile.StyleableSpannableStringBuilder.java
cz.nelasoft.opencms.mobile.WebContentFragment.java