|
|
|
@ -30,11 +30,13 @@ import net.micode.notes.data.Notes.NoteColumns;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
@ -45,12 +47,14 @@ public class FoldersListAdapter extends CursorAdapter {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
|
|
|
|
// 创建新的视图
|
|
|
|
|
return new FolderListItem(context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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);
|
|
|
|
@ -59,6 +63,7 @@ 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);
|
|
|
|
|
}
|
|
|
|
@ -68,11 +73,13 @@ public class FoldersListAdapter extends CursorAdapter {
|
|
|
|
|
|
|
|
|
|
public FolderListItem(Context context) {
|
|
|
|
|
super(context);
|
|
|
|
|
// 加载布局并初始化控件
|
|
|
|
|
inflate(context, R.layout.folder_list_item, this);
|
|
|
|
|
mName = (TextView) findViewById(R.id.tv_folder_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void bind(String name) {
|
|
|
|
|
// 设置文件夹名称
|
|
|
|
|
mName.setText(name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|