Я обновляю текст своего TextSwitcher в коде setViewValue. Но в случае, если значение базы данных не изменилось, я бы хотел избежать его обновления. Вот мой текущий код:
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
int viewId = view.getId();
switch(viewId) {
case R.id.timetext:
TextSwitcher twTime = (TextSwitcher) view;
// something is wrong in the next line
if (!cursor.getString(columnIndex).equals(getText(viewId)))
{
twTime.setText(cursor.getString(columnIndex));
}
return true;
Каким-то образом данные все еще обновляются. Почему?
Похоже, что getText()
работает неправильно с TextSwitcher
. Как получить его значение?
Хорошо, я нашел ответ.
Прежде всего, чтобы получить текст TextSwitcher
, следует использовать следующий код:
TextView tv = (TextView) twTime.getCurrentView();
if (!cursor.getString(columnIndex).equals(tv.getText().toString())) {
twTime.setText(cursor.getString(columnIndex));
}
но до этого
twTime.setCurrentText(cursor.getString(columnIndex));
.