我在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;不知何故,数据仍在更新。为什么?
看起来在TextSwitcher下getText()不能正常工作。如何获取其价值?
发布于 2011-05-23 01:40:53
好了,我找到答案了。首先,要获取TextSwitcher的文本,应该使用以下代码:
TextView tv = (TextView) twTime.getCurrentView();
if (!cursor.getString(columnIndex).equals(tv.getText().toString())) {
twTime.setText(cursor.getString(columnIndex));
}但在此之前
twTime.setCurrentText(cursor.getString(columnIndex));应该使用。
https://stackoverflow.com/questions/6089304
复制相似问题