Android execute code on variable change

前端 未结 2 714
-上瘾入骨i
-上瘾入骨i 2020-12-10 18:40

I alter a variable on different button clicks, (i.e. inside the onclick listener for multiple buttons) and I have a textview that is suppose to show this variable, but rema

2条回答
  •  忘掉有多难
    2020-12-10 19:01

    In C# there is an easy way to trigger some action once a variable changes so it is in Java. Java afaik do not support operators overloading, but this feature is not necessary. When it comes to classes (object) oriented programming, just create your special type out of any standard type. A new class will extend the features od any type (int, long, string, etc.). Define, for example your own "SET" and/or "GET" methods and just use these instead of standard "=" or get value/ponter as left operand.

    Example:

    public class myINT
    {
     public int Value;
    
     public void SET(int v) {Value = v;  // PLUS additional ACTION }
     public int  GET(int v) {return Value ;}
     public void ADD(int v) {Value += v; // PLUS additional ACTION }
     public void SUB(int v) {Value -= v; // PLUS additional ACTION }
    }
    

提交回复
热议问题