【问题标题】:How to avoid TextView/TextSwitcher update in setViewValue?如何避免 setViewValue 中的 TextView/TextSwitcher 更新?
【发布时间】:2011-05-23 01:40:52
【问题描述】:

我在 setViewValue 的代码中更新了我的 TextSwitcher 的文本。但是如果数据库值没有改变,我想避免它的更新。 这是我当前的代码:

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 一起正常工作。如何获得它的价值?

【问题讨论】:

    标签: android android-listview


    【解决方案1】:

    好的,我找到了答案。 首先要获取TextSwitcher的文本,应该使用以下代码:

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

    但在此之前

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

    应该使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-09
      • 1970-01-01
      • 1970-01-01
      • 2012-06-21
      • 2023-03-28
      • 1970-01-01
      相关资源
      最近更新 更多