![时间选择对话框 时间选择对话框](https://i-blog.csdnimg.cn/blog_migrate/a4c26d1e5885305701be709a3d33442f.gif)
![时间选择对话框 时间选择对话框](https://i-blog.csdnimg.cn/blog_migrate/a4c26d1e5885305701be709a3d33442f.gif)
.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
</RelativeLayout>
.java
package com.example.timerdialog;
import android.os.Bundle;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.TimePicker;
public class MainActivity extends Activity {
private Button mybut=null;
private TextView txt=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.mybut=(Button) super.findViewById(R.id.mybut);
this.txt=(TextView) super.findViewById(R.id.mytxt);
this.mybut.setOnClickListener(new OnClickListenerImp());
}
public class OnClickListenerImp implements OnClickListener{
public void onClick(View arg0) {
Dialog dialog=new TimePickerDialog(MainActivity.this, new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// TODO Auto-generated method stub
MainActivity.this.txt.setText("修改的时间为"+hourOfDay+":"+minute);
}
}, 14, 32, true);//设置默认时间
dialog.show();
}
}
}