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

Source: Internet
Author: User

Xutils Injection and picture display

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 FindControl to find him more cumbersome and difficult to maintain, and these use xutils can be very simple to complete, For example, we implement click Btn to assign a value to the text box:

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 Btn_testclick (View v)

{//method signature must be consistent with requirements in the interface

....

}

And the front desk doesn't need to define it:

<button

Android: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)

{//method signature must be consistent with requirements in the interface

Textview.settext ("Clicked Btn");

}

Second, the use of Xutils to complete the display of pictures

1. Network Image:

Need to increase network access rights

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

Bitmaputils bitmaputils = new Bitmaputils (this);

Bitmaputils.display (Imgitem, "http://42.121.254.191/images/logo_small.gif");

The idea is to declare the picture control first:

<imageview

Android: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;

Local images:

Put a picture in the local assets to be displayed.

Just one line of code:

Bitmaputils.display (Imgitem, "assets/qq.jpg");

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

Related Article

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.