Android form UI and event processing of corresponding controls, android form ui controls

Source: Internet
Author: User

Android form UI and event processing of corresponding controls, android form ui controls
1. ToastToast is a lightweight reminder tool that displays a line of text to prompt responses to user operations. Usage: Toast. makeText (context, text, time ). show (); context: context, text: display text content, time: Display duration Toast. LENGTH_SHORT (displayed in a short time) Toast. LENGTH_LONG (Displayed For A Long Time) Example: button = (Button) findViewById (R. id. button); button. setOnClickListener (new View. onClickListener () {@ Override public void onClick (View v) {Toast. makeText (ceshi. this, "you clicked", Toast. LENGTH_SHORT ). show () ;}}); 2. TextView-common types of text display controls TextColor text color textSize font size singleLine single line display true | falsegravity content center of gravity position drawableLeft text left show picture drawableRight text right show picture drawableTop text show above picture example of the image shown below the drawableBottom text: <TextView android: layout_width = "200dp" android: layout_height = "100dp" android: background = "#00ff00" android: id = "@ + id/textView2" android: layout_alignBottom = "@ id/f1" android: layout_centerInParent = "true" android: text = "laiyi bowl of fish balls" and Roid: textColor = "# f00" android: textSize = "20sp" android: gravity = "bottom | center"/> common methods nsetText () set the display text nsetTextColor () set the text color. The parameter is the color value nsetTextSize (). Set the text size. Parameter 1 is the size unit, and 2 is the size of ngetText () get the displayed Text 3. There is an onClick for the TextView attribute of the commonly used Button property, but this is generally not used. For the Button method, see the Toast usage above. 4. EditText-text input control, inherited from TextView common attribute inputType restrict the number of rows displayed in the booleanlines display when the prompt value displayed in the hint of the text type is stringmaxLength and the maximum length value that can be input is intfocusable The maximum number of lines displayed in ntmaxLines is intenable. For example, <EditText android: id = "@ + id/edittext_2" android: layout_width = "match_parent" android: layout_height = "wrap_content" android: hint = "enter the password! "Android: textSize =" 16sp "android: textColor =" # f00 "android: textColorHighlight =" # a00000ff "android: drawableLeft =" @ mipmap/ic_launcher "android: inputType = "textPassword"/> common methods setHint () Setting prompt text setInputType () Setting input restriction type setFocusable () Setting whether to get focus setEnable () Setting whether isEnable () is available () available code: edittext1.getText (). toString (); // obtain the EditView text value edittext1.addTextChangedListener (watcher); // The text listener private TextWatcher watcher = new TextWatcher () {/* Before text changes */@ Override public void beforeTextChanged (CharSequence s, int start, int count, int after) {}/* When the text changes */@ Override public void onTextChanged (CharSequence s, int start, int before, int count) {}/* after the text changes */@ Override public void afterTextChanged (Editable s) {// get the total number of input texts int currentCount = s. length (); // calculates the number of characters that can be entered. Remember, textview1.setText (String. valueOf (max-currentCount) ;}; 5. CheckBox -- check box, which inherits the attributes of TextView. The "button" check box indicates whether the "checked" button is selected. Example: <CheckBox android: id = "@ + id/checkbox3" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_below = "@ id/checkbox1" android: text = "Knock code"/> common methods TextView method setChecked () sets whether to select isChecked () Whether to select setOnCheckedChangeListener () sets the selected change listener specific code checkboxall. setOnCheckedChangeListener (changeListener); checkboxall. setChecked (false );

<! -- Layout --> <? Xml version = "1.0" encoding = "UTF-8"?> <RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: layout_width = "match_parent" android: layout_height = "match_parent" xmlns: app = "http://schemas.android.com/apk/res-auto"> <TextView android: id = "@ + id/textviewtitle" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_marginTop = "30dp" android: text = "What do you like to do? "/> <CheckBox android: id =" @ + id/checkboxall "android: layout_width =" wrap_content "android: layout_height =" wrap_content "android: layout_alignBottom = "@ id/textviewtitle" android: layout_alignTop = "@ id/textviewtitle" android: layout_toRightOf = "@ id/textviewtitle" android: text = "select all"/> <! -- Content CheckBox --> <CheckBox android: id = "@ + id/checkbox1" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_below = "@ id/textviewtitle" android: layout_marginRight = "80dp" android: text = ""/> <CheckBox android: id = "@ + id/checkbox2" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_below = "@ id/textviewtitle" android: layout_toRightOf = "@ + Id/checkbox1" android: text = ""/> <CheckBox android: id = "@ + id/checkbox3" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_below = "@ id/checkbox1" android: text = "Knock code"/> <CheckBox android: id = "@ + id/checkbox4" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_below = "@ id/checkbox2" android: layout_toRightOf = "@ + id/checkbox1" Ndroid: text = "running"/> <CheckBox android: id = "@ + id/checkbox5" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_below = "@ id/checkbox3" android: text = "swimming"/> <CheckBox android: id = "@ + id/checkbox6" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_below = "@ id/checkbox4" android: layout_toRightOf = "@ + id/checkbox1" android: text = "sleeping"/> <TextView android: id = "@ + id/textviewinfo" android: layout_width = "match_parent" android: layout_height = "wrap_content" android: layout_below = "@ id/checkbox5" android: layout_marginTop = "20dp" android: text = "selected:"/> </RelativeLayout> <! -- Java code --> package com. dc. work3; import android. OS. bundle; import android. support. v7.app. appCompatActivity; import android. util. log; import android. widget. checkBox; import android. widget. compoundButton; import android. widget. textView; import android. widget. toast; import java. util. using list; import java. util. list;/*** Created by blame Shu on 2016/11/4. */public class MainActivity2s extends AppCompatActivity {private CheckBox checkboxall; private CheckBox checkBox1; private CheckBox checkBox2; private CheckBox checkBox3; private CheckBox checkBox4; private CheckBox checkBox5; private CheckBox checkBox6; private TextView summary; private List <String> checkedStr; // when the operation is canceled, cancel all selected. This variable is whether the user clicks private boolean checkFoUser = true; protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main_2); checkboxall = (CheckBox) findViewById (R. id. checkboxall); checkBox1 = (CheckBox) findViewById (R. id. checkbox1); checkBox2 = (CheckBox) findViewById (R. id. checkbox2); checkBox3 = (CheckBox) findViewById (R. id. checkbox3); checkBox4 = (CheckBox) findViewById (R. id. checkbox4); checkBox5 = (CheckBox) findViewById (R. id. checkbox5); checkBox6 = (CheckBox) findViewById (R. id. checkbox6); textviewinfo = (TextView) findViewById (R. id. textviewinfo); checkBox1.setOnCheckedChangeListener (changeListener); listener (changeListener); checkboxall. setOnCheckedChangeListener (changeListener); checkedStr = new parameter list <> ();} public CompoundButton. onCheckedChangeListener changeListener = new CompoundButton. onCheckedChangeListener () {@ Override public void onCheckedChanged (CompoundButton buttonView, boolean isChecked) {switch (buttonView. getId () {case R. id. checkbox1: case R. id. checkbox2: case R. id. checkbox3: case R. id. checkbox4: case R. id. checkbox5: case R. id. checkbox6: String str = buttonView. getText (). toString (); if (isChecked) {checkedStr. add (str);} else {checkedStr. remove (str);} checkboxall. callback (null); if (checkBox1.isChecked () & checkBox2.isChecked () & checkBox3.isChecked () & checkBox4.isChecked () & checkBox5.isChecked () & checkBox6.isChecked ()) {// indicates that if all are selected, the Select All button is also selected as checkboxall. setChecked (true);} else {// otherwise, the All button is deselected, but this will trigger the checkboxall listener and cancel all the checkboxall. setChecked (false);} checkboxall. setOnCheckedChangeListener (changeListener); break; case R. id. checkboxall: if (checkFoUser) {checkBox1.setChecked (isChecked); checkBox2.setChecked (isChecked); checked (isChecked); Disabled (isChecked); checkBox6.setChecked (isChecked ); break ;}} StringBuffer sb = new StringBuffer (); for (String str: checkedStr) {sb. append (str + ",");} if (sb. length ()> 0) {// set the length to-1 and remove the last "," sb. setLength (sb. length ()-1);} textviewinfo. setText ("selected:" + sb. toString ());}};}

 

6. RadioButtonRadioGroup -- Single-choice button and single-choice group RadioButton -- Single-choice button, which are inherited from TextView and the same as CheckBox and often used together with RadioGroup to form a single-choice result RadioGroup -- Single-choice group, inherited from LinearLayout common attributes: commonly used method of LinearLayout attributes setOnCheckedChangeLinsener () internal single-choice button selected change listener check () selected subitem getCheckedRadioButtonId () to obtain the selected RadioButton idclearCheck () clear selected 7. ImageView -- image control common attributes src specify the size of the image adjustViewBounds control to be displayed only to the image range size maxHeight max height maxWidth max width scaleType scaling type nfitStart (Proportional Ratio) adaptive size at the beginning of the display) fitEnd (proportional adaptive size at the end) nfitXY (Adaptive Control xy size) fitCenter (proportional adaptive size in the middle) ncenter (according to the original image size in the center) centerCrop (proportional scaling to full control) ncenterInside (when the image is smaller than the control width, the Zoom is displayed in the middle; otherwise, the proportional scaling is displayed in the middle) nmatrix (the image is not scaled, the image is displayed in the upper left corner. You can use the setImageMatrix () method to operate the image)

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.