. NET Programmer for Android Learning 5: Using Xutils to inject view and events and picture display

Source: Internet
Author: User

Original:. NET Programmer for Android Learning 5: Using Xutils to inject view and events and picture display

Xutils injection and picture display one, xutils injection

Quote Official Introduction:

viewutils module: Android in the IOC framework, fully annotated mode can be UI, resource and event binding; • New event binding methods that work correctly when confused with obfuscation tools; • Currently supports 20 commonly used event bindings, See Viewcommoneventlistener class and package com.lidroid.xutils.view.annotation. event.

Before we write events such as BTN's Click event is generally hard-coded or linstener way to achieve, from the interface to the value of an element or assignment must first use the FindControl to find him more cumbersome and difficult to maintain, And these annotations using Xutils can be very concise, such as the following example we implement the click Btn to the Text box assignment operation:

After clicking BTN:

The first thing to achieve xutils injection is to include in the OnCreate:

Viewutils.inject (this// inject view and events

The control is then defined as follows:

@ViewInject (r.id.lbl_info) Private TextView TextView;

This is equivalent to finding a TextView with an interface ID of lbl_info , which is used arbitrarily in the following code:

Textview.settext ("Clicked Btn");

The ability to inject a view can also inject events, such as we want to implement the BTN click event just the following code:

@OnClick (r.id.btn_test)  Public void
The // method signature must be consistent with the requirements in the interface ... .}

The foreground does not need to define its events:

<buttonandroid:id="@+id/btn_test"android:layout_width="  wrap_content"android:layout_height="wrap_content"  Android:text="Show Me" />

Together It is:

@OnClick (r.id.btn_test)  Public void Btn_testclick (View v)    {         // The method signature must be consistent with the requirements in the interface        textview.settext ("Clicked Btn" );    }

This way you must ensure that the control has an ID.

Second, the use of Xutils to complete the display of pictures
? Bitmaputils module: • When loading the bitmap, there is no need to consider the phenomenon of image dislocation such as oom and the fast sliding of the Android container during the bitmap loading process; • Support for loading network pictures and local images; • Memory management uses the LRU algorithm, Better management of bitmap memory; • Configurable thread preempted number of threads, cache size, cache path, load display animation, etc...
1. Network Image:

Need to increase network or SD card access rights:

<uses-permission android:name="android.permission.INTERNET" />< Uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"

Take the blog Park logo as an example, access to the following code:

New Bitmaputils (this"http://42.121.254.191/images/logo_small.gif" );

The idea is to first declare the picture control in the interface:

<imageviewandroid:id="@+id/img_item"android:layout_width="  wrap_content"android:layout_height="wrap_content" />

Find this control again:

@ViewInject (R.id.img_item) Private ImageView Imgitem;

The code that will begin to access the network picture is placed under the button click event to run:

2. Local images

Put a picture in the local assets to be displayed.

Just one line of code (the rest and the previous example):

" assets/qq.jpg ");

. NET Programmer for Android Learning 5: Using Xutils to inject view and events and picture display

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.