Skip to content

Instantly share code, notes, and snippets.

@gabbsmo
Created August 29, 2013 14:40
Show Gist options
  • Save gabbsmo/6378970 to your computer and use it in GitHub Desktop.
Save gabbsmo/6378970 to your computer and use it in GitHub Desktop.
package com.example.photodiary;
import android.content.Context;
import android.view.*;
import android.app.*;
import android.widget.*;
import java.util.*;
public class DiaryAdapter extends BaseAdapter {
private Context mContext;
private int mLayoutResourceId;
private ArrayList<Entry> mEntries = null;
public DiaryAdapter(Context context, int layoutResourceId, ArrayList<Entry> entries) {
super();
mContext = context;
mLayoutResourceId = layoutResourceId;
mEntries = entries;
}
@Override
public View getView(int position, View row, ViewGroup parent) {
EntryHolder holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity)mContext).getLayoutInflater();
row = inflater.inflate(mLayoutResourceId, parent, false);
holder = new EntryHolder();
holder.titleText = (TextView)row.findViewById(R.id.textViewMasterTitle);
holder.createdAtText = (TextView)row.findViewById(R.id.textViewMasterCreatedAt);
Entry entry = mEntries.get(position);
holder.titleText.setText(entry.getTitle());
holder.createdAtText.setText(entry.getCreatedAt().toString());
row.setTag(holder);
} else {
holder = (EntryHolder)row.getTag();
}
return row;
}
private class EntryHolder {
public TextView titleText;
public TextView createdAtText;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return mEntries.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return mEntries.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return mEntries.get(position).getEntryId();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment