需求:例如一个数字翻转动画,需要在动画执行完后获取真实的返回值,然后再执行随后的程序。
?
动画播放完后执行回调:
?
1.首先新增回调接口
public interface Callback {
??void perform(int lastValue);
?}
?
2.应用回调接口
?public void increase(Callback c) {
??int curVal = Integer.parseInt((String) Anim3DTextView.this.getText());
??applyRotation(curVal+1, 0, 0, 180, c);
?}
?
?public void decrease(Callback c) {
??int numb = Integer.parseInt((String) Anim3DTextView.this.getText());
??if (!negative && numb>0) {
???applyRotation(numb-1, 0, 0, 180, c);
??}
?}?
?
3.在实际应用中添加实现
??increase3.setOnClickListener(new OnClickListener() {
???public void onClick(View v) {
????v_count3.increase(new Callback() {
?????public void perform(int lastValue) {
??????ShoppingCart.instance().increase(f3);
?????}
????});
???}
??});