|
|
|
|
@ -14,7 +14,7 @@
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package net.micode.notes.ui;
|
|
|
|
|
package net.micode.notes.ui; //该类所在的包名
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.database.Cursor;
|
|
|
|
|
@ -29,25 +29,30 @@ import net.micode.notes.data.Notes;
|
|
|
|
|
import net.micode.notes.data.Notes.NoteColumns;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FoldersListAdapter 类的定义,扩展了 CursorAdapter 类。
|
|
|
|
|
public class FoldersListAdapter extends CursorAdapter {
|
|
|
|
|
public static final String [] PROJECTION = {
|
|
|
|
|
NoteColumns.ID,
|
|
|
|
|
NoteColumns.SNIPPET
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 定义数据库查询的投影和列的索引
|
|
|
|
|
public static final int ID_COLUMN = 0;
|
|
|
|
|
public static final int NAME_COLUMN = 1;
|
|
|
|
|
|
|
|
|
|
// FoldersListAdapter 类的构造函数,它调用父类的构造函数。
|
|
|
|
|
public FoldersListAdapter(Context context, Cursor c) {
|
|
|
|
|
super(context, c);
|
|
|
|
|
// TODO Auto-generated constructor stub
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//CursorAdapter 类的一个方法的实现,用于创建新的列表项视图。
|
|
|
|
|
@Override
|
|
|
|
|
public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
|
|
|
|
return new FolderListItem(context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CursorAdapter 类的一个方法的实现,用于将数据绑定到列表项视图上。
|
|
|
|
|
@Override
|
|
|
|
|
public void bindView(View view, Context context, Cursor cursor) {
|
|
|
|
|
if (view instanceof FolderListItem) {
|
|
|
|
|
@ -57,12 +62,15 @@ public class FoldersListAdapter extends CursorAdapter {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 自定义方法,用于获取指定位置的文件夹名称
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FoldersListAdapter 类的一个内部类,用于表示列表项视图。它扩展了 LinearLayout 类,并维护了一个 TextView 来显示文件夹名称。
|
|
|
|
|
// bind() 方法用于将数据绑定到列表项视图上
|
|
|
|
|
private class FolderListItem extends LinearLayout {
|
|
|
|
|
private TextView mName;
|
|
|
|
|
|
|
|
|
|
|