Class 7 of Android-single-dataset, check box, pop-up box, and other control operations

Source: Internet
Author: User

These controls are commonly used, so they are commonly used during operations. Therefore, this part is an important part of Android software development and the content is relatively simple. Introduction to shard types

1. Single-stick operation: A single-stick operation can be seen everywhere in Android. It consists of two parts: radiogroup and radiobutton. A radiogroup contains multiple radiobutton instances. Each radiobutton is a single option, and the radiogroup is controlled. The following is the implementation of XML and code:

XML:

<Radiogroup <br/> Android: Id = "@ + ID/gendergroup" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: Orientation = "horizontal" <br/> </P> <p> <radiobutton <br/> Android: id = "@ + ID/femalebutton" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: TEXT = "@ string/female"/> </P> <p> <radiobutton <br/> Android: Id = "@ + ID/malebutton" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: text = "@ string/Male"/> <br/> </radiogroup>

A simple display of radiogroup and radiobutton is defined above.

The following is the operation code of the event bound to this control:

// Bind the oncheckedchangelistener of gendergroup to respond to the event <br/> gendergroup. setoncheckedchangelistener (New radiogroup. oncheckedchangelistener () {</P> <p> @ override <br/> Public void oncheckedchanged (radiogroup group, int checkedid) {<br/> If (femalebutton. GETID () = checkedid) {<br/> system. out. println ("female"); <br/> toast. maketext (activity07.this, "female", toast. length_short ). show (); <br/>} else if (malebutton. GETID () = checkedid) {<br/> system. out. println ("male"); <br/> toast. maketext (activity07.this, "male", toast. length_short ). show (); <br/>}< br/> });

2. the event in the pop-up box (toast) is similar to the joptionpane of swing, but it is called toast. The method used is to add toast where you need the pop-up information. maketext (here is the name of the class object to be popped up. This is the string to be popped up and the length to be popped up ). For more information, see the last line of the above Java code. The dialog box does not need to be configured in XML.

3. check box: the check box does not have the concept of a group as a single sequence, so the operations of the check box are a little more complex than those of a single sequence, because you need to make an Event Response for each check box. The following is an example of a check box.

<Checkbox <br/> Android: Id = "@ + ID/swim" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: text = "@ string/swim"/> </P> <p> <checkbox <br/> Android: id = "@ + ID/Run" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: TEXT = "@ string/Run"/> </P> <p> <checkbox <br/> Android: Id = "@ + ID/read" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: text = "@ string/read"/>

The following is the time response code:

// The Listener bound to the checkbox is different from the radiogroup method. <br/> specify checkbox. setoncheckedchangelistener (New compoundbutton. oncheckedchangelistener () {</P> <p> @ override <br/> Public void oncheckedchanged (compoundbutton buttonview, Boolean ischecked) {<br/> If (ischecked) {<br/> system. out. println ("swim is checked"); <br/>} else {<br/> system. out. println ("swim is unchecked"); <br/>}< br/>}); <br/> runcheckbox. setoncheckedchangelistener (New compoundbutton. oncheckedchangelistener () {</P> <p> @ override <br/> Public void oncheckedchanged (compoundbutton buttonview, Boolean ischecked) {<br/> If (ischecked) {<br/> system. out. println ("Run is checked"); <br/>} else {<br/> system. out. println ("Run is unchecked"); <br/>}< br/>}); <br/> readcheckbox. setoncheckedchangelistener (New compoundbutton. oncheckedchangelistener () {</P> <p> @ override <br/> Public void oncheckedchanged (compoundbutton buttonview, Boolean ischecked) {<br/> If (ischecked) {<br/> system. out. println ("read is checked"); <br/>} else {<br/> system. out. println ("read is unchecked"); <br/>}< br/> });

 

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.