2

I update the text of my TextSwitcher in the code of setViewValue. But in case database value is not changed, I would like to avoid its update. Here is my current code:

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;

Somehow, the data is still updated. Why?

Looks like getText() doesn't work properly with TextSwitcher. How to get its value?

LA_
  • 19,823
  • 58
  • 172
  • 308

1 Answers1

3

Ok, I found the answer. First of all to get the text of TextSwitcher the following code should be used:

TextView tv = (TextView) twTime.getCurrentView();
if (!cursor.getString(columnIndex).equals(tv.getText().toString())) {
    twTime.setText(cursor.getString(columnIndex));
}

but prior to that

twTime.setCurrentText(cursor.getString(columnIndex));

should be used.

LA_
  • 19,823
  • 58
  • 172
  • 308