?? Everything in Java is object. Whether you're a thread, an asynchronous task, or ... You can use the following three common methods to interact with data between objects. Of course, Android has its own unique way of interacting with data compared to Java, which is described in a later article, which is intended to summarize the data interactions between common Java objects.
First, passing through the constructor function
?? The constructor is largely a convenient way to pass the parameters, in order to initialize some properties of the object at the time of the new object. We often need to overload the constructor of a class to suit our needs. We can pass the data it needs to the object when it is first built to enable the interaction of data between different objects.
Second, getxxx and Setxxx methods
?? Based on the encapsulation and security considerations in Java object-oriented programming, we often encapsulate the member variables in the class inside the class (that is, using private to decorate them), which improves the security of the data, what if we want to manipulate these member variables? We can use two methods, the first is the public way of the constructor (or constructor), that is, the content of the method, the object of an instantiation of the variable is assigned value. The second approach is through the set and get methods.
?? When we write the Pojo class, we usually set the corresponding get and set methods to the member variables.
?? In fact, the application scenarios of get and set are not limited to this, our thinking can not be limited. In Android, activity wants handler in a child thread, we can write a gethandler method to the child thread, and then call the Gethander method in the activity with the child thread object, we can get the handler of the child thread.
?? Also, the ListView encountered a checkbox, we will build a map in the adapter to store the state of the checkbox, in the activity, in the full selection, cancellation of the button listening method, we need to take the adapter map, and then update the map. The solution is: Write a Getmap method in adapter.
Third, interface callback
?? The previous blog in this section has been described in detail: http://blog.csdn.net/a910626/article/details/45920893
Data interaction between different Java objects (common)