Android Note 1

Source: Internet
Author: User

Start to read the summary of the book "advanced for Android mobile development.

1 <button Android: text = "@ + ID/button01">
When a new button is added, @ must tell the XML parser to parse the part after the ID character,
When referencing an android ID, you do not need the "+" sign, as shown in the following code:
Android: Id = "@ Android: ID/button01

CodeTo get a button:
Button mybutton = (button) findviewbyid (R. Id. my_button );

2 tablelayout example:
<Tablelayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent" Android: layout_height = "fill_parent"
Android: stretchcolumns = "1">

<Tablerow>
<Textview Android: text = "User name:" Android: textstyle = "bold"
Android: gravity = "right" Android: padding = "3dip"/>

<Edittext Android: Id = "@ + ID/username" Android: padding = "3dip"
Android: scrollhorizontally = "true"/>
</Tablerow>

<Tablerow>
<Textview Android: text = "Logon password:" Android: textstyle = "bold"
Android: gravity = "right" Android: padding = "3dip"/>

<Edittext Android: Id = "@ + ID/password" Android: Password = "true"
Android: padding = "3dip" Android: scrollhorizontally = "true"/>
</Tablerow>

<Tablerow Android: gravity = "right">

<Button Android: Id = "@ + ID/cancel"
Android: text = "cancel"/>

<Button Android: Id = "@ + ID/login"
Android: text = "login"/>
</Tablerow>
</Tablelayout>
3 Example of relative_layout
<Relativelayout
Xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent" Android: layout_height = "wrap_content"
Android: Background = "@ drawable/Blue" Android: padding = "10dip">

<Textview Android: Id = "@ + ID/label" Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content" Android: text = "Enter the User name:"/>

<! --
This edittext is placed under the textview with the label ID.
-->
<Edittext Android: Id = "@ + ID/entry" Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: Background = "@ Android: drawable/editbox_background"
Android: layout_below = "@ ID/label"/>

<! --
The cancel button is flat to the right of the container and the left margin is set to 10dip.
-->
<Button Android: Id = "@ + ID/cancel" Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content" Android: layout_below = "@ ID/entry"
Android: layout_alignparentright = "true"
Android: layout_marginleft = "10dip" Android: text = "cancel"/>

<! --
The confirm button is on the left side of the cancel button, and the height of the cancel button is equal
-->
<Button Android: Id = "@ + ID/OK" Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_toleftof = "@ ID/cancel"
Android: layout_aligntop = "@ ID/cancel" Android: text = "OK"/>

</Relativelayout>

4. Process users' click events. This is simple.
Button0 = (button) findviewbyid (R. Id. button0 );
Button0.setonclicklistener (listener0 );
Listener0 = new onclicklistener (){
Public void onclick (view v ){
Intent intent0 = new intent (activitymain. This, activityframelayout. Class );
Settitle ("framelayout ");
Startactivity (intent0 );
}
};

5. Access the image resource named A1 in the Res/drawable directory.
Drawable d = This. getresources (). getdrawable (R. drawable. A1 );

6 menu operations
Public Boolean oncreateoptionsmenu (menu ){
Super. oncreateoptionsmenu (menu );
Menu. Add (0, item0, 0, "Show button1 ");
Menu. Add (0, Item1, 0, "Show button2 ");
Menu. finditem (Item1 );
Return true;
}
 
Public Boolean onoptionsitemselected (menuitem item ){
Switch (item. getitemid ()){
Case item0:
Actionclickmenuitem1 ();
Break;
Case Item1:
Actionclickmenuitem2 (); break;

}
Return super. onoptionsitemselected (item );}

7. Obtain the value passed by the previous activety:
Intent intent = getintent ();
String name = (string) intent. getextras (). Get ("name ");
For example, if you enter the value name in a text box, click button1 to bring up a dialog box that passes the name value, you can do this:
Btn_dialog.setonclicklistener (New onclicklistener (){
Public void onclick (view v ){
// PASS Parameters through intent
Intent intent = new intent ();
Intent. putextra ("name", edittext. gettext (). tostring ());
// Start another activity
Intent. setclass (multiactivity. This, alertdialog. Class );
Startactivity (intent );
}
});
Put the parameter value with putextra and start a new activety with startactivety

 

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.