Detailed explanation of how to use xutils3 framework in Android (I)

Introduction to xutils

Xutils contains many useful Android tools.

Xutils supports large file upload, more comprehensive HTTP request protocol support (10 predicates), more flexible ORM, more event annotation support, and is not affected by confusion

Xuitls is at least compatible with Android 2.2 (API level 8)

Today I'll bring you a basic introduction to xutils3. The cases in this article are based on the API syntax of xutils3. I'm sure you all know this framework,

Here is a brief introduction to some basic knowledge of xutils3.

Xutils3 has four major functions: annotation module, network module, image loading module and database module.

To use xutils, you only need to add a jar package in the LIBS folder. If you package the data returned by the server, you also need to import a gson jar package.

Annotation module

Comments for activity

1. Add the following code to the oncreate method of application:

x.Ext. init(this);

2. Add the following code to the oncreate method of activity:

x.view(). inject(this);

3. The following comments are required to load the current activity layout:

@Add contentview to the top of activity

4. The following comments are required to initialize the view:

@InjectView

5. The following comments are required to handle various response events of the control:

@Envent

Through the test, we found that when clicking BTN_ When you click get, the "send get request" effect pops up. So far, you have a basic understanding of xutils annotation. What I emphasize below is that @ event annotation has the type attribute of view by default OnClickListener. class. If you want to achieve the effect of other click events, you only need to modify the type value.

In addition, it should be noted that the click event of the button must be decorated with private.

Comments on fragment:

Comments for viewholder:

The above code is the standard mode of annotation viewholder. I believe you can fully understand it. Here I use xutils3's method of loading network pictures to load pictures. I'll explain it in detail later.

Network module

Xutils' network request method is very similar to the usage of some network request frameworks. I have made some simple encapsulation.

There are three files in the package: the network request tool class xutil, the request response data parsing class, and an interface callback class for successful requests.

The code is as follows:

1. Example of sending get request:

2. Send a post request

3. Upload files

4. Download files

5. Download file with progress bar

6. Send get request (returned by the server in XML format)

Picture loading module

Usage:

The API of xutils3 is relatively simple. I believe you can understand it. The first parameter is passed into a view, the second parameter is passed into the network address of an image, and the third parameter is generally the configuration of loading images.

Let's take a look at the imageoptions class:

For other configurations, please refer to the source code

If you need to operate on the loaded picture, you can use:

The returned drawable object is used for image processing to meet the personalized requirements of the project

Having said so much, I think you will at least have a basic understanding of xutils3. Because there are many uses of xutils3 database, this article will not cover it. In the next article, I will explain the database module of xutils3 in detail. Let's do it now! All examples involved in this article will be covered in the following demo. Please refer to them yourself.

Related reading:

Use xutils3 0 to download project updates

Detailed explanation of basic usage rules after Android xutils is updated to 3.0

The above is a detailed explanation of the use of xutils3 framework in Android (I) introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>