I'm trying to update a TextView
(let's call it name
) from the SwitchCompat
's OnCheckedChanged()
method. The problem is that right after I call name.setText()
, the animation that moves SwitchCompat's thumb button interrupts and the thumb button just hops to another side. Here's the sample:
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
name.setText("Some name");
}
I also tried to use Handler
to post my updates and it turns out that if I post before the animation is done, it will still be interrupted. For example, if the animation takes 1000 ms
and I call postDelayed()
with the delay of 500 ms
, the thumb button smoothly moves to the middle of the SwitchCompat
and then just hops. Code:
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
name.setText("Some name");
}
}, 500);
Both views are the parts of a single layout (which represents a ListView
item):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:addStatesFromChildren="true"
android:descendantFocusability="blocksDescendants"
android:paddingBottom="5dp">
<TableLayout
android:id="@+id/mainPanel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="0">
<TableRow>
<android.support.v7.widget.SwitchCompat
android:id="@+id/isAlarmOn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"/>
</TableRow>
</TableLayout>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/mainPanel" />
</RelativeLayout>
So how do I change that TextView
without breaking the animation?