Package loujin. Android;
Import java. util. calendar;
Import Android. App. activity;
Import Android. App. datepickerdialog;
Import Android. App. timepickerdialog;
Import Android. OS. Bundle;
Import Android. View. view;
Import Android. widget. adapterview;
Import Android. widget. arrayadapter;
Import Android. widget. Button;
Import Android. widget. datepicker;
Import Android. widget. multiautocompletetextview;
Import Android. widget. spinner;
Import Android. widget. textview;
Import Android. widget. timepicker;
Public class androidprojectactivity extends activity {
Private Static final string [] m_countries = {"Information System", "Trade System", "electromechanical system", "tourism system", "light Spinning System", "Industrial and Commercial Department "};
Private Static final string [] autostring = {"textview", "listview", "tost", "edittext", "radiogroup ",
"Radiobutton", "checkbox", "Spinner", "autocompletetextview", "image", "imagebutton "};
Private textview m_textview, k_textview, d_textview, t_textview;
Private spinner m_spinner;
Private arrayadapter <string> adapter;
Button m_dpbutton;
Button m_tpbutton;
Calendar C;
/** Called when the activity is first created .*/
@ Override
Public void oncreate (bundle savedinstancestate)
{
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
Multiautocompletetextview mm_autocompletetextview = (multiautocompletetextview) findviewbyid (R. Id. multiautocompletetextview01 );
// Add the adapter to autocompletetextview
Mm_autocompletetextview.setadapter (adapter );
Mm_autocompletetextview.settokenizer (New multiautocompletetextview. commatokenizer ());
M_textview = (textview) findviewbyid (R. Id. textview1 );
M_spinner = (spinner) findviewbyid (R. Id. spinner1 );
K_textview = (textview) findviewbyid (R. Id. textview2 );
// Time
C = calendar. getinstance ();
D_textview = (textview) findviewbyid (R. Id. textview3 );
T_textview = (textview) findviewbyid (R. Id. textview4 );
M_dpbutton = (button) findviewbyid (R. Id. button1 );
M_tpbutton = (button) findviewbyid (R. Id. button2 );
// Connect the available content to the arrayadapter
Adapter = new arrayadapter <string> (this, Android. R. layout. simple_spinner_item, m_countries );
// Set the style of the drop-down list
Adapter. setdropdownviewresource (Android. R. layout. simple_spinner_dropdown_item );
// Add the adapter to m_spinner
M_spinner.setadapter (adapter );
// Add event listening
M_spinner.setonitemselectedlistener (new Spinner. onitemselectedlistener (){
@ Override
Public void onitemselected (adapterview <?> Arg0, view arg1, int arg2, long arg3)
{
M_textview.settext ("your system is:" + m_countries [arg2]);
// Set to display the selected items
Arg0.setvisibility (view. Visible );
}
@ Override
Public void onnothingselected (adapterview <?> Arg0)
{
// Todo auto-generated method stub
}
});
// Prompt box
Arrayadapter <string> adapter = new arrayadapter <string> (this,
Android. R. layout. simple_dropdown_item_1line, autostring );
Multiautocompletetextview mm_autocompletetextview1 = (multiautocompletetextview) findviewbyid (R. Id. multiautocompletetextview01 );
// Add the adapter to autocompletetextview
Mm_autocompletetextview1.setadapter (adapter );
Mm_autocompletetextview1.settokenizer (New multiautocompletetextview. commatokenizer ());
// Set the time
M_dpbutton.setonclicklistener (New button. onclicklistener (){
Public void onclick (view V)
{
New datepickerdialog (androidprojectactivity. This,
New datepickerdialog. ondatesetlistener ()
{
Public void ondateset (datepicker view, int year, int monthofyear, int dayofmonth)
{
// Set the calendar
T_textview.settext ("the date you set is:" + year + "year" + (monthofyear + 1) + "month" + dayofmonth + "day ");
// Set to display the selected items
View. setvisibility (view. Visible );
}
}, C. Get (calendar. Year), C. Get (calendar. month), C. Get (calendar. day_of_month). Show ();
}
});
M_tpbutton.setonclicklistener (New button. onclicklistener (){
Public void onclick (view V)
{
New timepickerdialog (androidprojectactivity. This,
New timepickerdialog. ontimesetlistener ()
{
Public void ontimeset (timepicker view, int hourofday, int minute)
{
// Set the time
D_textview.settext ("the time you set is:" + hourofday + "point" + minute + "Minute ");
// Set to display the selected items
View. setvisibility (view. Visible );
}
}, C. Get (calendar. hour_of_day), C. Get (calendar. Minute), true). Show ();
}
});
}
}
<? XML version = "1.0" encoding = "UTF-8"?>
<Relativelayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: Id = "@ + ID/relativelayout1"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: filtertoucheswhenobscured = "true"
Android: Orientation = "vertical">
<Button
Android: Id = "@ + ID/button1"
Android: layout_width = "77dp"
Android: layout_height = "wrap_content"
Android: layout_alignparentleft = "true"
Android: layout_centervertical = "true"
Android: text = "date"/>
<Textview
Android: Id = "@ + ID/textview4"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: layout_above = "@ + ID/button1"
Android: layout_alignparentleft = "true"
Android: layout_marginbottom = "14dp"
Android: text = "@ string/textview4"/>
<Multiautocompletetextview
Android: Id = "@ + ID/multiautocompletetextview01"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: layout_above = "@ + ID/textview4"
Android: layout_alignparentleft = "true"
Android: layout_marginbottom = "16dp"/>
<Textview
Android: Id = "@ + ID/textview1"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: layout_alignparentleft = "true"
Android: layout_alignparenttop = "true"
Android: text = "@ string/Hello"/>
<Textview
Android: Id = "@ + ID/textview2"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: layout_above = "@ + ID/multiautocompletetextview01"
Android: layout_alignparentleft = "true"
Android: text = "@ string/textview2"/>
<Spinner
Android: Id = "@ + ID/spinner1"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_alignparentleft = "true"
Android: layout_below = "@ + ID/textview1"
Android: layout_margintop = "14dp"/>
<Button
Android: Id = "@ + ID/button2"
Android: layout_width = "77dp"
Android: layout_height = "wrap_content"
Android: layout_alignparentleft = "true"
Android: layout_below = "@ + ID/button1"
Android: layout_margintop = "64dp"
Android: text = "time"/>
<Textview
Android: Id = "@ + ID/textview3"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: layout_alignparentleft = "true"
Android: layout_below = "@ + ID/button1"
Android: layout_margintop = "30dp"
Android: text = "@ string/textview3"/>
</Relativelayout>