Android EditText Control Learning from scratch

Source: Internet
Author: User

Class Structure:

Note: EditText is a type of control that can be edited and input. It can be seen from the class structure diagram that it is a subclass of TextView. Therefore, it has some attributes of TextView. Below is an example of EditText.

Practical drills:
1. How to set a maximum of N characters
Set by: android: maxLength

<EditText
 
Android: layout_width = "fill_parent"
 
Android: layout_height = "wrap_content"
 
Android: hint = "prompt text"
 
Android: maxLength = "4"
 
 
 
/>

Effect: only four words can be entered.


 
2. How do I set that only numbers can be entered?
Android: numeric has the following values: integer signed decimal.

<EditText android: id = "@ + id/myETxt02" android: layout_width = "fill_parent"
 
Android: layout_height = "wrap_content" android: numeric = "integer"/>
 

 
3. How do I set the password to the input format?
By setting android: password = "true", you can
 

<EditText android: id = "@ + id/myETxt02" android: layout_width = "fill_parent"
 
Android: layout_height = "wrap_content" android: password = "true"/>

Effect:
 
4. How to set the status to uneditable?
Method 1: android: editable = "false"

<EditText android: id = "@ + id/myETxt04" android: layout_width = "fill_parent"
 
Android: layout_height = "wrap_content" android: editable = "false"
 
Android: text = "editable"/>


Method 2:

MyEditText05 = (EditText) findViewById (R. id. myETxt05 );
 
// Set to uneditable
 
MyEditText05.setEnabled (false );

 
This is equivalent to the TextView control.

From: jiahui524 Column
 

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.