Xutils = = = basic usage of xutils3 framework

Reprinted from: http://blog.csdn.NET/a1002450926/article/details/50341173

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've all understood this framework. Let's briefly introduce 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 of 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: @ contentview is added to the top of the activity. 4. The following comments are required to initialize the view: @ injectview 5. The following comments are required to process various response events of the control: @ event

Through the test, we found that when clicking BTN_ When you click get, the "send get request" effect pops up. At this point, you have a basic understanding of xutils annotation. What I emphasize below is that the @ event annotation has a type attribute of view.onclicklistener.class by default. If you want to achieve the effects 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.

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)

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:

x.image().loadDrawable(url,imageOptions,new Callback.CommonCallback<Drawable>() {...});

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.

Source code download address: http://download.csdn.net/detail/a1002450926/9364413

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
分享
二维码
< <上一篇
下一篇>>