diff --git a/src/main/java/net/micode/notes/ui/NotesListAdapter.java b/src/main/java/net/micode/notes/ui/NotesListAdapter.java index 62d1da6..b35a085 100644 --- a/src/main/java/net/micode/notes/ui/NotesListAdapter.java +++ b/src/main/java/net/micode/notes/ui/NotesListAdapter.java @@ -34,6 +34,7 @@ import java.util.Iterator; public class NotesListAdapter extends CursorAdapter { private static final String TAG = "NotesListAdapter"; private Context mContext; + /** 键-值对,值为true时,表示被选中 @zhoukexing 2024/1/2 20:50 */ private HashMap mSelectedIndex; private int mNotesCount; private boolean mChoiceMode; @@ -78,6 +79,17 @@ public class NotesListAdapter extends CursorAdapter { mChoiceMode = mode; } + /** + * @method: selectAll + * @description: 传入一个boolean值, + * 通过setCheckedItem来修改mSelectedIndex数据成员, + * 将值都置为传入的参数, + * 达到选中所有项 or 不选所有项的效果。 + * @date: 2024/1/3 22:36 + * @author: zhoukexing + * @param: [checked] + * @return: void + */ public void selectAll(boolean checked) { Cursor cursor = getCursor(); for (int i = 0; i < getCount(); i++) { @@ -143,6 +155,18 @@ public class NotesListAdapter extends CursorAdapter { return count; } + public int getMNotesCount() { + return mNotesCount; + } + + /** + * @method: isAllSelected + * @description: 如果都选中了就返回true,否则返回false + * @date: 2024/1/2 20:47 + * @author: zhoukexing + * @param: [] + * @return: boolean + */ public boolean isAllSelected() { int checkedCount = getSelectedCount(); return (checkedCount != 0 && checkedCount == mNotesCount);