Technical Summary-android (1) -- MVC model, -- android -- mvc
First, we will introduce the MVC mode. The full name of MVC is Model View Controller, short for model-view-controller. It is a Model of software design, organize Code by means of separation of business logic, data, and interface display, and integrate the business logic into a component to improve and personalize the custom interface and user interaction, you do not need to rewrite the business logic. MVC is uniquely developed to map traditional input, processing, and output functions in a logical graphical user interface structure.
Using the MVC mode to write code makes the code more beautiful, easier to manage, and more scalable.
For Android, the MVC mode is also used.
1. the XML file on the interface is View (V );
2. The model layer includes data operations and network processing,
3. The controller layer is the logic processing for the activity, but the data and network logic processing in the model must be cut off, because the time-consuming processing is on the main thread, after processing for more than 5 seconds, ANR will appear (an android mechanism for app recycling during timeout.
My code structure:
I will not recreate a project, so I will explain it from the existing project. ignore other packages first.
The activities package (View), as its name implies, contains all the activities and corresponds to fragment. The code implementation is as follows:
Public class AdminAddGoodsActivity extends BaseFramActivty {@ Overrideprotected void onCreate (Bundle bundle) {super. onCreate (bundle); initTitle ("add item", 1, 0, new TitleImgClick () {@ Overridepublic void OnTitleImgClick (com. views. lib. tab. interfaces. method method) {switch (method) {case left: AndroidUtils. isGiveUpEdit (AdminAddGoodsActivity. this); break; case right: break; default: break ;}}); switchFram (new AddGoodsFragment ());}}Here BaseFramActivity and switchFram are implemented in Lib, which will be discussed later. We will keep them first.
The Activity in the Code corresponds to AddGoodsFragment, which implements interface initialization.
The adapter package is an important link between the Data and the UI (View). It intuitively expresses the relationship among Data, Adapter, and View. It mainly implements data initialization such as list.
Config.
Dao and ctrler (controller) are used to implement business logic processing with the model layer. Through this class, data is obtained and then returned to the activity for data display.
Db is the operation of the database.
Model, that is, some entity classes.
Utils, which contains some tool classes.
View, which is a custom view class
This is a summary of the code structure using the MVC mode in android.