开发者

How to avoid TextView/TextSwitcher update in setViewValue?

开发者 https://www.devze.com 2023-03-07 11:11 出处:网络
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.

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 开发者_C百科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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消