Android Open Source - MyJournal Journal Adapter






From Project

Back to project page MyJournal.

License

The source code is released under:

GNU General Public License

If you think the Android project MyJournal 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 com.shane87.myjournal;
//from  w w  w .  ja  v a  2  s . c  o m
import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class JournalAdapter extends BaseAdapter 
{
  private Context appContext;
  private ArrayList<JournalEntry> entries;
  private LayoutInflater inflater;
  
  public JournalAdapter(Context context, ArrayList<JournalEntry> e)
  {
    appContext = context;
    entries = e;
    inflater = LayoutInflater.from(appContext);
  }
  
  private static class JournalViewHolder
  {
    TextView titleView;
    TextView dateView;
  }
  
  @Override
  public int getCount()
  {
    return entries.size();
  }
  
  @Override
  public Object getItem(int position)
  {
    return entries.get(position);
  }
  
  @Override
  public long getItemId(int position)
  {
    return position;
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent)
  {
    JournalViewHolder viewHolder;
    
    if (convertView == null)
    {
      convertView = inflater.inflate(R.layout.entry_layout, parent, false);
      viewHolder = new JournalViewHolder();
      viewHolder.titleView = (TextView) convertView.findViewById(R.id.titleTextView);
      viewHolder.dateView = (TextView) convertView.findViewById(R.id.dateTextView);
      convertView.setTag(viewHolder);
    }
    else
    {
      viewHolder = (JournalViewHolder) convertView.getTag();
    }
    
    JournalEntry entry = entries.get(position);
    
    viewHolder.titleView.setText(entry.getTitle());
    viewHolder.dateView.setText(entry.getDate());
    
    return convertView;
  }
}




Java Source Code List

com.shane87.myjournal.EditEntryActivity.java
com.shane87.myjournal.JournalAdapter.java
com.shane87.myjournal.JournalContract.java
com.shane87.myjournal.JournalDbHelper.java
com.shane87.myjournal.JournalEntry.java
com.shane87.myjournal.Journal.java
com.shane87.myjournal.MainActivity.java