Android - 使用 SimpleCursorAdapter 时在列表视图中设置编辑文本
Android - Setting edittext in a listview when using SimpleCursorAdapter
我想做的是更改每个 listItem 中 1 个 edittext 的值。即 DueDate 作为 dateString 01/01/2016 来自数据库,我想将它更改为从现在到现在之间有多少天,而不是当它出现在 listView 中时。
我需要获取它设置为现在的值,并通过一种方法发送它来计算从现在到那时之间的天数,这很简单,但问题是当使用 cursorAdapter 时,没有我可以编辑 edittext 的循环.
getValues 填充列表的方法
final String[] from = new String[]{"_id", "ProjectSubject", "ProjectTitle", "ProjectWorth", "ProjectDueDate", "ProjectDetails"};
final int[] to = new int[]{R.id.IdText, R.id.SubjectTextList, R.id.ProjectTitleTextList, R.id.WorthText, R.id.DueDateTextList, R.id.DetailsTextList};
Cursor cursor = dbHelper.fetchAllProjects();
dataAdapter = new SimpleCursorAdapter(context, R.layout.summary_list_item,cursor,from, to, 0);
list.setAdapter(dataAdapter);
获取项目的适配器方法
public Cursor fetchAllProjects() {
Cursor mCursor = mDb.query(SQLITE_TABLE, new String[]{
KEY_ID,
KEY_SUBJECT,
KEY_TYPE,
KEY_TITLE,
KEY_WORTH,
KEY_DUEDATE,
KEY_DETAILS,
KEY_EMAIL},
null, null, null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
编辑 -
dataAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if (columnIndex == 5) {
((TextView) dueDateText).setText(cursor.getString(columnIndex) + " modified");
return true;
} else {
return false;
}
}
});
你应该使用 ViewBinder
例如
dataAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if(columIndex==3) {
((TextView)view).setText(cursor.getString(columnIndex)+" modified");
return true;
} else {
return false;
}
}
}
我想做的是更改每个 listItem 中 1 个 edittext 的值。即 DueDate 作为 dateString 01/01/2016 来自数据库,我想将它更改为从现在到现在之间有多少天,而不是当它出现在 listView 中时。
我需要获取它设置为现在的值,并通过一种方法发送它来计算从现在到那时之间的天数,这很简单,但问题是当使用 cursorAdapter 时,没有我可以编辑 edittext 的循环.
getValues 填充列表的方法
final String[] from = new String[]{"_id", "ProjectSubject", "ProjectTitle", "ProjectWorth", "ProjectDueDate", "ProjectDetails"};
final int[] to = new int[]{R.id.IdText, R.id.SubjectTextList, R.id.ProjectTitleTextList, R.id.WorthText, R.id.DueDateTextList, R.id.DetailsTextList};
Cursor cursor = dbHelper.fetchAllProjects();
dataAdapter = new SimpleCursorAdapter(context, R.layout.summary_list_item,cursor,from, to, 0);
list.setAdapter(dataAdapter);
获取项目的适配器方法
public Cursor fetchAllProjects() {
Cursor mCursor = mDb.query(SQLITE_TABLE, new String[]{
KEY_ID,
KEY_SUBJECT,
KEY_TYPE,
KEY_TITLE,
KEY_WORTH,
KEY_DUEDATE,
KEY_DETAILS,
KEY_EMAIL},
null, null, null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
编辑 -
dataAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if (columnIndex == 5) {
((TextView) dueDateText).setText(cursor.getString(columnIndex) + " modified");
return true;
} else {
return false;
}
}
});
你应该使用 ViewBinder
例如
dataAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if(columIndex==3) {
((TextView)view).setText(cursor.getString(columnIndex)+" modified");
return true;
} else {
return false;
}
}
}