Android Open Source - SimpleNotes Notes Adapter






From Project

Back to project page SimpleNotes.

License

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.

Java Source Code

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;
    }
}




Java Source Code List

com.moysa.simplenotes.core.Note.java
com.moysa.simplenotes.core.NotesComparator.java
com.moysa.simplenotes.core.NotesUtils.java
com.moysa.simplenotes.db.NoteDataBaseHelper.java
com.moysa.simplenotes.ui.activities.MainActivity.java
com.moysa.simplenotes.ui.activities.SettingsActivity.java
com.moysa.simplenotes.ui.adapters.NotesAdapter.java
com.moysa.simplenotes.ui.application.NoteApplication.java
com.moysa.simplenotes.ui.fragments.NavigationDrawerFragment.java
com.moysa.simplenotes.ui.fragments.NoteFragment.java
com.moysa.simplenotes.ui.listeners.ListHeaderAnimationListener.java