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