[英]Android - Setting edittext in a listview when using SimpleCursorAdapter
What im trying to do is change the value of 1 edittext in each listItem. 我想做的是在每个listItem中更改1 edittext的值。 ie the DueDate is coming from database as a dateString 01/01/2016 and i want to change it to how many days are between now and then instead when it appears in the listView. 即DueDate作为dateString 01/01/2016来自数据库,我想将其更改为从现在到现在之间有多少天,而不是当它出现在listView中时。
I need to get the value its set to now and send it through a method to calculate the days between now and then which is easy enough but the problem is when using a cursorAdapter theres no loop that i can edit the edittext. 我需要立即获取其设置的值,并通过一种方法将其发送,以计算从现在到现在之间的天数,这很容易,但是问题是当使用cursorAdapter时,没有循环可以编辑edittext。
getValues Method which fills the list 填充列表的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);
Adapter method which fetches the projects 获取项目的适配器方法
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;
}
Edit - 编辑-
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;
}
}
});
You should use ViewBinder 您应该使用ViewBinder
eg 例如
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;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.