1
我試圖做的是更改每個listItem中的1個edittext的值。即DueDate作爲dateString 01/01/2016來自數據庫,我想將其更改爲現在和之後多少天,而不是當它出現在listView中時。Android - 在使用SimpleCursorAdapter時在列表視圖中設置edittext
我需要獲取它現在設置的值,並通過一個方法發送它來計算現在和之間的日期,這很容易,但問題是使用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;
}
}
});
謝謝我仍然認爲我是錯的。我編輯了原文。我正在嘗試調用虛方法'void android.widget.TextView.setText(java.lang.CharSequence)',它指向dueDateText的空對象引用 – user237462
對不起,我之前做過一個拼寫錯誤,爲了你的代碼, dueDateText' with'view' –
太好了。謝謝。林相當肯定我可以從這裏得到它。非常感激。 – user237462