本文介绍了如何避免setViewValue中的TextView/TextSwitcher更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用setViewValue的代码更新了TextSwitcher的文本.但是,如果数据库值未更改,我想避免对其进行更新.这是我当前的代码:
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?
类似getText()
不能与TextSwitcher
一起正常工作.如何获得其价值?
Looks like getText()
doesn't work properly with TextSwitcher
. How to get its value?
推荐答案
好,我找到了答案.首先要获取TextSwitcher
的文本,应使用以下代码:
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));
}
但在此之前
twTime.setCurrentText(cursor.getString(columnIndex));
应该使用.
这篇关于如何避免setViewValue中的TextView/TextSwitcher更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!