用户点击 产看班级数据 后
代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SelectActivity">
<EditText
android:id="@+id/date"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="16sp"
android:textColor="#008B00"
android:hint="请选择日期"
android:background="@drawable/bg_username"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:maxLines="1"
android:layout_marginTop="250dp"
android:drawableRight="@drawable/icon_calendar"
android:layout_marginHorizontal="20dp"/>
<Button
android:id="@+id/queren"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="50dp"
android:text="确认"
android:textSize="16sp"
android:background="@drawable/bg_btn4"
android:layout_below="@+id/date"
android:layout_centerInParent="true"
android:layout_marginTop="20dp" />
</RelativeLayout>
相对应的 activity.java
package com.example.myapplication; import android.app.DatePickerDialog; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.DatePicker; import android.widget.EditText; import android.widget.LinearLayout; import androidx.appcompat.app.AppCompatActivity; import java.util.Calendar; public class SelectActivity extends AppCompatActivity { private Calendar calendar; // 通过Calendar获取系统时间 private int mYear, mMonth, mDay; private LinearLayout layoutDate; private EditText date; private Button queren; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_select); date = findViewById(R.id.date); calendar = Calendar.getInstance(); date.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new DatePickerDialog(SelectActivity.this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int month, int day) { // TODO Auto-generated method stub mYear = year; mMonth = month; mDay = day; // 更新EditText控件日期 小于10加0 date.setText(new StringBuilder() .append(mYear) .append("-") .append((mMonth + 1) < 10 ? "0" + (mMonth + 1) : (mMonth + 1)) .append("-") .append((mDay < 10) ? "0" + mDay : mDay)); } }, calendar.get(Calendar.YEAR), calendar .get(Calendar.MONTH), calendar .get(Calendar.DAY_OF_MONTH)).show(); } }); queren = findViewById(R.id.queren); queren.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String DATE = date.getText().toString(); //跳转界面 Intent intent = new Intent(SelectActivity.this, ShowActivity1.class); intent.putExtra("DATE",DATE); SelectActivity.this.startActivity(intent); } }); } }