Android Development Learning Essays

Source: Internet
Author: User

(a), TextView

1. Display text information using TextView

2. Define the label of the constant under the Resources tab

3. Get the control object through the Findviewbyid () method, this method returns a View object that requires a type cast

4. Be sure to refer to the appropriate layout before you get a control object

5, dynamic access to resource constant value needs to obtain resources object, resources object through the Getresources () method to obtain

(b), monitor button click event

Comparison of 3 registered monitoring methods

    • Anonymous inner class: Need to get control object, use variable inconvenient; Apply to single event
    • Implement interface: Need to get control object, use variable convenient; apply to multiple events
    • Set the OnClick property: No need to get control object, use variable conveniently; not easy to maintain

(c) Layout

Role: Invisible View container primary key, which is responsible for managing the position and size of its child controls displayed on the screen

There are several common types:

Linear layout: Linear layout child controls are arranged horizontally or vertically

Arrange Direction Properties:

Horizontal layout (default) android:orientation= "Horizontal" (No Line wrapping)

Vertical layout: android:orientation= "Vertical"

Gravity attribute Android:gravity

Center Horizontal vertical Center Center_horizontal Horizontal center Center_ Vertical Vertical Center

Top&bottom Top & Bottom Left&right left & on right

Relative layout: The Relativelayout child control is flexible in a particular location, and it is convenient to describe the relative position relationship of the control to the control

Frame layout: Framelayout sub-controls are cascade-covered relationships, and are used in situations where sliding pages and fragments appear

Grid layout: GridLayout sub-controls are arranged in a table

One, the control

button--can set a button for text content

imagebutton--can not set the text content, you can add a imag through background and SRC, the current picture can be a text content picture.

ImageButton is used to display a picture on a button. So there is no android:text this attribute. And if you write android:text= " I am a button " in the layout file, you will not see any effect in the Android 4.4 environment.

(b), monitor button click event

Comparison of 3 registered monitoring methods

    • Anonymous inner class: Need to get control object, use variable inconvenient; Apply to single event
    • Implement interface: Need to get control object, use variable convenient; apply to multiple events
    • Set the OnClick property: No need to get control object, use variable conveniently; not easy to maintain

1), Autocomplptetextview function: Dynamically match the input content

unique attribute:android:completionthreshold= "2" sets the number of characters to automatically match when entering

Example:

2),Mulitautocomplptetextview function: can support the selection of multiple values, separated by separators, can be used for text messages and messages when selecting contacts.

unique attribute:android:completionthreshold= "2" sets the number of characters to automatically match when entering

Example:

<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
Android:id= "@+id/activity_main"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:orientation= "Vertical"
tools:context= "Com.demo.MainActivity" >

<autocompletetextview
Android:completionthreshold= "2"
Android:id= "@+id/autocompletetextview"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:hint= "Please enter keyword"/>

<multiautocompletetextview
android:completionthreshold= "1"
Android:id= "@+id/autocompletetextview2"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
Android:hint= "Please enter your recipient"/>
</LinearLayout>

Package Com.demo;

Import android.app.Activity;
Import Android.os.Bundle;
Import Android.widget.ArrayAdapter;
Import Android.widget.AutoCompleteTextView;
Import Android.widget.MultiAutoCompleteTextView;

public class Mainactivity extends Activity {

Private Autocompletetextview Actextview;
Private Multiautocompletetextview Mactextview;

Private string[] res = {"Nanning", "Nanning 2", "Liuzhou", "Guilin", "Beihai"};
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
/**
* 1. Initialize the control
* 2, create an adapter,
* 3, initialize the data source, this data source to and text box input content to match
* 4, bind adapter with Autocompletetextview
*/
actextview= (Autocompletetextview) Findviewbyid (R.id.autocompletetextview);
arrayadapter<string> adapter = new Arrayadapter<string> (this,android. R.layout.simple_list_item_1,res);
Actextview.setadapter (adapter);


/**
* Multiautocompletetextview
* 1. Initialize the control
* 2, create an adapter,
* 3, initialize the data source, this data source to and text box input content to match
* 4, bind adapter with Autocompletetextview
* 5, set the delimiter
*/
Mactextview = (Multiautocompletetextview) Findviewbyid (R.ID.AUTOCOMPLETETEXTVIEW2);
Mactextview.setadapter (adapter);
Set the end delimiter as a comma
Mactextview.settokenizer (New Multiautocompletetextview.commatokenizer ());
}
}


Android Development Learning Essays

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.