Data interaction between different java objects (common) and java Interaction
Everything in java is an object. Whether you are a thread, asynchronous task, or... You can use the following three common methods to exchange data between objects. Of course, android has its own unique data interaction method compared with java. These will be discussed in later articles. This article aims to summarize the data interaction between common java objects.
1. pass through Constructor
The struct constructor is very convenient for parameter passing, so that some attributes of the object are initialized when the object is created. We often need to reload the constructor of classes according to our own needs. When an object is created, we can pass the required data to it to realize data interaction between different objects.
2. 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 (that is, modify them using private ), this improves data security. What should we do when we want to operate these member variables? We can use two methods. The first method is the public Constructor (or constructor), that is, the content described in method 1. when an object is instantiated, the variable is assigned a value. The second method is through the set and get methods.
When writing a pojo class, we usually set the get and set methods for the member variables.
In fact, the application scenarios of get and set are not limited, so our thinking cannot be limited. In android, if the activity wants to get handler from the sub-thread, we can write a getHandler Method to the sub-thread, and then call the getHander method with the object of the sub-thread in the activity, you can get the handler of the sub-thread.
Callback callback. When a checkbox is encountered in listview, we will create a map in the adapter to store the status of the checkbox. In the activity, in the listener method of all selected and canceled buttons, we need to get the map of the adapter and then update the map. Solution: Write A getMap method in the adapter.
Iii. Interface callback
This part of the previous blog has been described in detail: http://blog.csdn.net/a910626/article/details/45920893