The path to Android development-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. Below is the implementation of XML and code

XML:

  1. <Radiogroup
  2. Android: Id = "@ + ID/gendergroup"
  3. Android: layout_width = "wrap_content"
  4. Android: layout_height = "wrap_content"
  5. Android: Orientation = "horizontal"
  6. >
  7. <Radiobutton
  8. Android: Id = "@ + ID/femalebutton"
  9. Android: layout_width = "wrap_content"
  10. Android: layout_height = "wrap_content"
  11. Android: text = "@ string/female"/>
  12. <Radiobutton
  13. Android: Id = "@ + ID/malebutton"
  14. Android: layout_width = "wrap_content"
  15. Android: layout_height = "wrap_content"
  16. Android: text = "@ string/Male"/>
  17. </Radiogroup>

A simple display of radiogroup and radiobutton is defined above.

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

  1. // Bind the oncheckedchangelistener of gendergroup to respond to the event
  2. Gendergroup. setoncheckedchangelistener (NewRadiogroup. oncheckedchangelistener (){
  3. @ Override
  4. Public VoidOncheckedchanged (radiogroup group,IntCheckedid ){
  5. If(Femalebutton. GETID () = checkedid ){
  6. System. Out. println ("female ");
  7. Toast. maketext (activity07.This, "Female", Toast. length_short). Show ();
  8. }Else If(Malebutton. GETID () = checkedid ){
  9. System. Out. println ("male ");
  10. Toast. maketext (activity07.This, "Male", Toast. length_short). Show ();
  11. }
  12. }
  13. });

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.

  1. <Checkbox
  2. Android: Id = "@ + ID/swim"
  3. Android: layout_width = "wrap_content"
  4. Android: layout_height = "wrap_content"
  5. Android: text = "@ string/swim"/>
  6. <Checkbox
  7. Android: Id = "@ + ID/run"
  8. Android: layout_width = "wrap_content"
  9. Android: layout_height = "wrap_content"
  10. Android: text = "@ string/run"/>
  11. <Checkbox
  12. Android: Id = "@ + ID/read"
  13. Android: layout_width = "wrap_content"
  14. Android: layout_height = "wrap_content"
  15. Android: text = "@ string/read"/>

The following is the time response code:

  1. // The Listener bound to the checkbox is different from the radiogroup method.
  2. Inclucheckbox. setoncheckedchangelistener (NewCompoundbutton. oncheckedchangelistener (){
  3. @ Override
  4. Public VoidOncheckedchanged (compoundbutton buttonview,BooleanIschecked ){
  5. If(Ischecked ){
  6. System. Out. println ("swim is checked ");
  7. }Else{
  8. System. Out. println ("swim is unchecked ");
  9. }
  10. }
  11. });
  12. Runcheckbox. setoncheckedchangelistener (NewCompoundbutton. oncheckedchangelistener (){
  13. @ Override
  14. Public VoidOncheckedchanged (compoundbutton buttonview,BooleanIschecked ){
  15. If(Ischecked ){
  16. System. Out. println ("Run is checked ");
  17. }Else{
  18. System. Out. println ("Run is unchecked ");
  19. }
  20. }
  21. });
  22. Readcheckbox. setoncheckedchangelistener (NewCompoundbutton. oncheckedchangelistener (){
  23. @ Override
  24. Public VoidOncheckedchanged (compoundbutton buttonview,BooleanIschecked ){
  25. If(Ischecked ){
  26. System. Out. println ("read is checked ");
  27. }Else{
  28. System. Out. println ("read is unchecked ");
  29. }
  30. }
  31. });
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.