Android Open Source - Note Note Adapter

From Project

Back to project page Note.


The source code is released under:

MIT License

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

// w  w w. j  a  v a  2s  .co  m
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;


import android.content.Context;
import android.database.Cursor;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;

public class NoteAdapter extends CursorAdapter {
  private HashMap<Integer, Boolean> mSelectedIndex;
  private boolean mChoiceMode;

  public NoteAdapter(Context context, Cursor c, boolean autoRequery) {
    super(context, c, autoRequery);
    mSelectedIndex = new HashMap<Integer, Boolean>();

  public void bindView(View view, Context context, Cursor cursor) {
    if (view instanceof NotesListItem) {
      long id = cursor.getLong(0);
      Note data = NoteApplication.daoSession.getNoteDao().load(id);
      ((NotesListItem) view).bind(context, data, mChoiceMode,

  public View newView(Context context, Cursor cursor, ViewGroup parent) {
    return new NotesListItem(context);

  public void setChoiceMode(boolean mode) {
    mChoiceMode = mode;

  public void setCheckedItem(final int position, final boolean checked) {
    mSelectedIndex.put(position, checked);

  public boolean isInChoiceMode() {
    return mChoiceMode;

  public HashSet<Long> getSelectedItemIds() {
    HashSet<Long> itemSet = new HashSet<Long>();
    for (Integer position : mSelectedIndex.keySet()) {
      if (mSelectedIndex.get(position) == true) {
        Long id = getItemId(position);
    return itemSet;

  public int getSelectedCount() {
    Collection<Boolean> values = mSelectedIndex.values();
    if (null == values) {
      return 0;
    Iterator<Boolean> iter = values.iterator();
    int count = 0;
    while (iter.hasNext()) {
      if (true == {
    return count;

  public boolean isSelectedItem(final int position) {
    if (null == mSelectedIndex.get(position)) {
      return false;
    return mSelectedIndex.get(position);


Java Source Code List