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.
精彩评论