记账本开发5
public class Add extends AppCompatActivity
{ private EditText time; @Override protected void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState); setContentView(R.layout.activity_add); time = findViewById(R.id.time); time.seta(new View.OnTouchListener()
{ @Override public boolean onTouch(View v, MotionEvent m)
{ if (m.getAction() == MotionEvent.ACTION_DOWN)
{ show(); return true; } return false; } }); time.setb(new View.OnFocusChangeListener()
{ @Override public void onFocusChange(View v, boolean f)
{if (f) {show();}} }); } protected void show()
{ Calendar cal=Calendar.getInstance(); DatePickerDialog dataPickerDialog=new DatePickerDialog(AddActivity.this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { AddActivity.this.time.setText(year+"-"+(month+1)+"-"+dayOfMonth); } },cal.get(Calendar.YEAR),cal.get(Calendar.MONTH),cal.get(Calendar.DAY_OF_MONTH)); dataPickerDialog.show(); }
今天根据博客、CSDN、百度等修改了时间功能。