Checkbox:
Declaration in XML
<Checkbox <br/> Android: Id = "@ + ID/mycheckbox" <br/> Android: layout_width = "97px" <br/> Android: layout_height = "wrap_content" <br/> Android: text = "@ string/str_agree" <br/> Android: layout_x = "99px" <br/> Android: layout_y = "318px" <br/>
Define in activity:
Mycheckbox = (checkbox) findviewbyid (R. Id. mycheckbox );
Add a listener event:
Mycheckbox. setonclicklistener (New checkbox. onclicklistener () <br/>{< br/> @ override <br/> Public void onclick (view V) <br/>{< br/> // todo auto-generated method stub <br/> If (mycheckbox. ischecked () <br/>{< br/>/* set the button to an object that cannot be selected */<br/> mybutton. setenabled (true); <br/> mytextview2.settext (""); <br/>}< br/> else <br/> {<br/>/* set the button to an object that can be selected */<br/> mybutton. setenabled (false); <br/> mytextview1.settext (R. string. text1); <br/>/* In textview2, "check" */<br/> mytextview2.settext (R. string. no); <br/>}< br/> });
Multiple checkboxes can be used to construct multiple checkboxes.
Radiogroup and radiobutton:
XML declaration, radiogroup puts the radiobutton package in it:
<Radiogroup <br/> Android: Id = "@ + ID/myradiogroup" <br/> Android: layout_width = "137px" <br/> Android: layout_height = "216px" <br/> Android: Orientation = "vertical" <br/> Android: layout_x = "3px" <br/> Android: layout_y = "54px" <br/> <! -- The First radiobutton --> <br/> <radiobutton <br/> Android: Id = "@ + ID/myradiobutton1" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: TEXT = "@ string/tr_radio_op1" <br/> <! -- The second radiobutton --> <br/> <radiobutton <br/> Android: Id = "@ + ID/myradiobutton2" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: TEXT = "@ string/tr_radio_op2" <br/> </radiogroup>
Definition in activity:
Mradiogroup1 = (radiogroup) findviewbyid (R. id. myradiogroup); <br/> mradio1 = (radiobutton) findviewbyid (R. id. myradiobutton1); <br/> mradio2 = (radiobutton) findviewbyid (R. id. myradiobutton2 );
Listener function:
Private radiogroup. oncheckedchangelistener mchangeradio = new <br/> radiogroup. oncheckedchangelistener () <br/>{< br/> @ override <br/> Public void oncheckedchanged (radiogroup group, int checkedid) <br/> {<br/> // todo auto-generated method stub <br/> If (checkedid = mradio1.getid ()) <br/> {<br/>/* upload the content of mradio1 to mtextview1 */<br/> mtextview1.settext (mradio1.gettext ()); <br/>}< br/> else if (checkedid = mradio2.getid ()) <br/> {<br/>/* upload the content of mradio2 to mtextview1 */<br/> mtextview1.settext (mradio2.gettext ()); <br/>}< br/> };
Use mradiogroup1.clearcheck (); to cancel the selection
Imageview:
The key lies in the getresources () method. This method is used to access the resource ID. getresources () is used to access image files and text in the resource. getresources () is used here (). getdrawable () is used to load image files in RES/drawable and place the images in imageview.
Mimageview1.setimagedrawable (getresources (). getdrawable (R. drawable. Right ));
Use setalpha (int A); To set transparency
In addition, create two imageviews. One is the outer box and the other is the inner box. The image needs to be sorted in a stack order, and the foreground image is placed above (with absolutelayout). The background image is placed below the foreground image, this is the simplest method of stack sequence. Imagebutton can also be made into a stack, so that there are not only background images, but also button events.
Use the spinner and arrayadapter together to construct the spinner:
// Define the arraylist to store entries <br/> allcountries = new arraylist <string> (); <br/> for (INT I = 0; I <countriesstr. length; I ++) <br/>{< br/> allcountries. add (countriesstr [I]); <br/>}< br/> // defines the arrayadapter object and passes in the arraylist. <br/> adapter = new arrayadapter <string> (this, <br/> android. r. layout. simple_spinner_item, allcountries); <br/> adapter <br/>. setdropdownviewresource <br/> (Android. r. layout. simple_spinner_dropdown_item); </P> <p> // set the spinner to the adapter <br/> myspinner. setadapter (adapter );