//get the system time
Val simpleDateFormat1=SimpleDateFormat (" yyyy ")
Val date1=Date (System. CurrentTimeMillis ())
Var datay=simpleDateFormat1. The format (date1) toInt ()
//time? SetText (simpleDateFormat. The format (date))
Val simpleDateFormat2=SimpleDateFormat (" MM ")
Val date2=Date (System. CurrentTimeMillis ())
Val datam=simpleDateFormat2. The format (date2) toInt ()
//"access control"
Val sp_year: Spinner=the findViewById (R.i d.s p_year)
Val sp_month: Spinner=the findViewById (R.i d.s p_month)
//for the Spinner load data
"1. Prepare data
"Val year=arrayOf (datay datay - 1, datay - 2)
Val month=arrayOf (
ArrayOf (datam, 1,2,3,4,5,6,7,8,9,10,11,12),
,2,3,4,5,6,7,8,9,10,11,12 arrayOf (1),
ArrayOf,2,3,4,5,6,7,8,9,10,11,12 (1)
)
"2. The data is loaded into the data adapter parameters a context two each line three data format parameters"
Val year_adapter=ArrayAdapter (this, android R.l ayout. Simple_spinner_item, year)
"3. Give Spinner data adapter object"
Sp_year. Adapter=year_adapter
//set to monitor response to an event for Spinner
Sp_year. OnItemSelectedListener=object: AdapterView. OnItemSelectedListener {
Override fun onNothingSelected (parent: AdapterView<* & gt; ?). {}
Override fun onItemSelected (
Parent: AdapterView<* & gt; ? ,
View: the view? ,
Position: Int,
Id: Long
) {
Sp_year_positon=position
//position: Int, it is the Spinner each location id
"The city of data through the adapter to spinner"
Val month_adapter=ArrayAdapter (
This @ MainActivity,
Android. R.l ayout simple_spinner_item,
The month [position]
)
Sp_month. Adapter=month_adapter
//Toast. MakeText (this @ ThirdActivity, country [position], Toast. LENGTH_LONG), show ()
}
}
//set to monitor response to an event for Spinner
Sp_month. OnItemSelectedListener=object: AdapterView. OnItemSelectedListener {
Override fun onNothingSelected (parent: AdapterView<* & gt; ?). {}
Override fun onItemSelected (
Parent: AdapterView<* & gt; ? ,
View: the view? ,
Position: Int,
Id: Long
) {}
}
Var n=sp_year. GetSelectedItem (). The toString ()
Var y=sp_month. GetSelectedItem (). The toString ()
Getalldata (n, y)
SetAdapter ()
Toast. MakeText (this, n, Toast. LENGTH_SHORT.) the show ()
Toast. MakeText (this, y, Toast. LENGTH_SHORT.) the show ()