【发布时间】:2017-10-07 08:50:10
【问题描述】:
我的工具栏中有一个 TextView,这个 TextView 显示一个选定的日期(例如,2017 年 10 月 7 日,星期六)。这个工具栏在我的 MainActivity 中,在这个 MainActivity 里面我有一个带有 ListView 的片段。此 ListView 使用 ContentResolver 链接到我的 SQLiteDatabase,并且此数据库中的值按日期过滤。
我有以下问题:我希望每当我更改 MainActivity 工具栏中的 TextView 时,我的 Fragment 中的 CursorLoader 都会得到通知。
例如:我将日期 (TextView) 设置为 2017 年 10 月 6 日,ListView 会显示从 6 月 6 日开始的所有条目。
我在 TextView 上使用 TextWatcher 进行了尝试,但它不起作用(不知道我必须如何设置 TextChangeListener),我使用 Cursor Loader 的 onContentChanged() 方法进行了尝试。
没有什么对我有用...也许你有一个想法。
编辑:
只是为了更好的理解。我的日期变量是 public static final 所以我可以在 CursorLoader 中访问。我的 Fragment CursorLoader 中的选择如下:
String selection = DoingContract.COLUMN_DATE + "=?";
String[] selectionArgs = {MainActivity.mDate};
日期变量的更新方式如下:
public void setupToolbar(String date) {
mDate = date;
mToolbarTextView.setText(mDate);
}
setupToolbar 方法中的日期参数来自我的 DatePicker Dialog:
public void onDateSet(DatePicker datePicker, int year, int month, int day) {
Calendar newDate = Calendar.getInstance();
newDate.set(year, month, day);
String date = mDateFormat.format(newDate.getTime());
if (main != null) {
main.setupToolbar(date);
} else {
entry.setupDate(date);
}
}
【问题讨论】:
标签: android sqlite android-textwatcher