Android development and learning notes (7) Android Application Interface Programming Radio/check/datapicker Learning

Source: Internet
Author: User

In this test, you can enter a table. The table structure is as follows. The entire table is tablelayout. The first row has an edittext, the second row has a list of radiobutton's horizontal, and the third row is a datapicker, the fourth line is the linearlayout list of a checkbox, and the fifth line is a textview, which shows the current time learned from the system.

Source code:

Layout file:

<Tablelayout xmlns: Android = "http://schemas.android.com/apk/res/android" xmlns: Tools = "http://schemas.android.com/tools" Android: layout_width = "match_parent" Android: layout_height = "match_parent"> <tablerow> <textview Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "name"/> <edittext Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: hint = "type your name"/> </tablerow> <textview Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: TEXT = "sex"/> <radiogroup Android: Id = "@ + ID/RP" Android: Orientation = "horizontal"> <radiobutton Android: layout_height = "wrap_content" Android: layout_width = "wrap_content" Android: text = "male" Android: checked = "true" Android: Id = "@ + ID/Male"/> <radiobutton Android: layout_height = "wrap_content" Android: layout_width = "wrap_content" Android: text = "female" Android: id = "@ + ID/female"/> </radiogroup> </tablerow> <textview Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: TEXT = "Birthday"/> <datepicker Android: Id = "@ + ID/datepicker" Android: startyear = "1970" Android: layout_height = "wrap_content" Android: layout_width = "wrap_content" Android: layout_gravity = "Hangzhou"/> </tablerow> <textview Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: TEXT = "interest"/> <linearlayout Android: Orientation = "vertical" Android: layout_gravity = "center_horizontal" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content"> <checkbox Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "A" Android: checked = "true"/> <checkbox Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "B" Android: checked = "false"/> <checkbox Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "C" Android: checked = "false"/> </linearlayout> </tablerow> <linearlayout Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: orientation = "vertical"> <textview Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: id = "@ + ID/TXT"/> </linearlayout> </tablelayout>

JAVA Code :

Package COM. xujin. checktest; import Java. util. calendar; import android. app. activity; import android. OS. bundle; import android. view. menu; import android. widget. datepicker; import android. widget. textview; public class mainactivity extends activity {private int year; private int month; private int day; private int hour; private int min; @ overrideprotected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. activity_main); datepicker = (datepicker) findviewbyid (R. id. datepicker); Calendar c = calendar. getinstance (); year = C. get (calendar. year); month = C. get (calendar. month); Day = C. get (calendar. day_of_month); hour = C. get (calendar. hour); min = C. get (calendar. minute); show (year, month, day, hour, min);} private void show (INT year, int month, int day, int hour, int min) {textview show((textview1_findviewbyid(r.id.txt); show. settext ("data:" + year + "year" + month + "month" + day + "day" + hour + "Hour" + min + "Minute ");} @ overridepublic Boolean oncreateoptionsmenu (menu) {// inflate the menu; this adds items to the action bar if it is present. getmenuinflater (). inflate (R. menu. activity_main, menu); Return true ;}}

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.