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 ;}}