Chris .... Here is the easiest way to develop an application. Divide the problem into three parts. Presentation or presentation. Algorithm or model. A controller that responds to user and system events. This creates a “separation of concerns” so that the Controller owns the view and model. You create a view using xml, as in main.xml. You create a separate class to do the work, say MyModel.java, and of course there is a controller or an Activity class, say MyActivity.java. Thus, the data comes from a model entering the controller, which updates the view.
So your question is how to get data from the model and update the view. Naturally, this will happen in the controller, in your activity. The easiest way to do this is to put the button in action, and when the user clicks the button, call model.getLatestData () and update the view. This is PULLing data. The next way is to ensure that the Controller checks for updates every minute. This is POLLING for data. The next way is for the Controller to register interest in the model changes and wait for the model to report the change and then update the view. This is an asynchronous transfer of data from the model to the controller and can be performed using the OBSERVER template.
I know that this makes no sense to you when you struggle with trying to just get the code to work, but I hope I put the seed of an idea in your head that will bother you and make sense someday in the future.
Jal
Jal
source share