From da4fa905b1dd24d8bcf4560cdfc53dccbb8b21f0 Mon Sep 17 00:00:00 2001 From: wyf <18818870625@163.com> Date: Sun, 24 Dec 2023 20:48:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=B2=E5=AE=8C=E6=88=90=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/FoldersListAdapter.java | 112 ++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 doc/FoldersListAdapter.java diff --git a/doc/FoldersListAdapter.java b/doc/FoldersListAdapter.java new file mode 100644 index 0000000..ae8c08a --- /dev/null +++ b/doc/FoldersListAdapter.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.micode.notes.ui; + +import android.content.Context; +import android.database.Cursor; +import android.view.View; +import android.view.ViewGroup; +import android.widget.CursorAdapter; +import android.widget.LinearLayout; +import android.widget.TextView; + +import net.micode.notes.R; +import net.micode.notes.data.Notes; +import net.micode.notes.data.Notes.NoteColumns; + +/** + * @ProjectName: FoldersListAdapter + * @Package: net.micode.notes.ui + * @ClassName: FoldersListAdapter + * @Description: 设置文件夹的控制变量 + * @Author: wyf + * @CreateDate: 2023/12/24 20:31 + */ +//CursorAdapter是Cursor和ListView的接口 +//FoldersListAdapter继承了CursorAdapter的类 +//主要作用是便签数据库和用户的交互 +//这里就是用folder(文件夹)的形式展现给用户 +public class FoldersListAdapter extends CursorAdapter { + public static final String [] PROJECTION = { + NoteColumns.ID, + NoteColumns.SNIPPET//调用数据库中便签的ID和片段 + }; + + public static final int ID_COLUMN = 0; + public static final int NAME_COLUMN = 1; + + public FoldersListAdapter(Context context, Cursor c) { + super(context, c);//数据库操作 + // TODO Auto-generated constructor stub + } + + @Override + public View newView(Context context, Cursor cursor, ViewGroup parent) { + return new FolderListItem(context);//创建一个文件夹,对于各文件夹中子标签的初始化 + } + /** + * @method: bindView + * @description:将各个布局文件绑定起来 + * @date: 2023/12/24 20:40 + * @author: wyf + * @param: class\interface + * @return: void + */ + @Override + public void bindView(View view, Context context, Cursor cursor) { + if (view instanceof FolderListItem) { + String folderName = (cursor.getLong(ID_COLUMN) == Notes.ID_ROOT_FOLDER) ? context + .getString(R.string.menu_move_parent_folder) : cursor.getString(NAME_COLUMN); + ((FolderListItem) view).bind(folderName); + } + } + + public String getFolderName(Context context, int position) { + Cursor cursor = (Cursor) getItem(position); + return (cursor.getLong(ID_COLUMN) == Notes.ID_ROOT_FOLDER) ? context + .getString(R.string.menu_move_parent_folder) : cursor.getString(NAME_COLUMN); + }//根据数据库中标签的ID得到标签的各项内容 + + private class FolderListItem extends LinearLayout { + private TextView mName; + /** + * @ProjectName: FolderListItem + * @Package: net.micode.notes.ui + * @ClassName: FolderListItem + * @Description: 设置文件夹各项目 + * @Author: wyf + * @CreateDate: 2023/12/24 20:42 + */ + public FolderListItem(Context context) { + super(context);//操作数据库 + inflate(context, R.layout.folder_list_item, this);//根据布局文件的名字等信息将其找出来 + mName = (TextView) findViewById(R.id.tv_folder_name); + } + /** + * @method: bind + * @description:设置显示名称 + * @date: 2023/12/24 20:46 + * @author: wyf + * @param: string + * @return: void + */ + public void bind(String name) { + mName.setText(name); + } + } + +}