Back to project page SimpleNotes.
The source code is released under:
Apache License
If you think the Android project SimpleNotes listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.moysa.simplenotes.ui.adapters; // w w w . j a va2s. com import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; import com.moysa.simplenotes.R; import com.moysa.simplenotes.core.Note; import com.moysa.simplenotes.ui.application.NoteApplication; import java.text.ParseException; import java.util.List; /** * Created by Sergey Moysa on 25.02.14. */ public class NotesAdapter extends BaseAdapter { private List<Note> mNotes; private LayoutInflater mInflater; private int mRecource; public NotesAdapter(Context context, int resource) { mNotes = NoteApplication.getInstance().getNotes(); this.mRecource = resource; mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } public void setNotes(List<Note> notes) { mNotes = notes; this.notifyDataSetChanged(); } public void add(Note object) { mNotes.add(0, object); this.notifyDataSetChanged(); } public void remove(Note object) { mNotes.remove(object); this.notifyDataSetChanged(); } @Override public int getCount() { return mNotes.size(); } @Override public Object getItem(int position) { return mNotes.get(position); } @Override public long getItemId(int position) { return mNotes.get(position).getId(); } @Override public View getView(int position, View convertView, ViewGroup parent) { try { ViewHolder viewHolder = new ViewHolder(); Note note = mNotes.get(position); if (convertView == null) { convertView = mInflater.inflate(mRecource, null); viewHolder.name = (TextView) convertView.findViewById(R.id.note_name); viewHolder.time = (TextView) convertView.findViewById(R.id.note_time); convertView.setTag(viewHolder); } else { viewHolder = (ViewHolder) convertView.getTag(); } viewHolder.name.setText(note.getName()); viewHolder.time.setText(note.getTime()); } catch (ParseException e) { //TODO handle exception e.printStackTrace(); } return convertView; } public List<Note> getNotes() { return mNotes; } public static class ViewHolder { TextView name; TextView time; } }