为什么timepickerdialog对话框不显示
publicclassMainActivityextendsActivity{Calendarcalendear=null;TextViewtv;Buttonbtn;fi...
public class MainActivity extends Activity {
Calendar calendear=null;
TextView tv;
Button btn;
final int MYDIALOG=1;
@Override
@Deprecated
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
Dialog dialog=null;
switch (id) {
case MYDIALOG:
Builder builde=new AlertDialog.Builder(this);
calendear=Calendar.getInstance();
dialog=new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// TODO Auto-generated method stub
tv.setText("您设置的时间为:"+hourOfDay+"点"+minute+"分");
}
}, calendear.get(Calendar.HOUR_OF_DAY), calendear.get(Calendar.MINUTE), true);
dialog=builde.create();
break;
default:
break;
}
return dialog;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
super.onCreate(savedInstanceState);
tv=(TextView)findViewById(R.id.textView1);
btn=(Button)findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
@SuppressWarnings("deprecation")
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
showDialog(MYDIALOG);
}
});
} 展开
Calendar calendear=null;
TextView tv;
Button btn;
final int MYDIALOG=1;
@Override
@Deprecated
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
Dialog dialog=null;
switch (id) {
case MYDIALOG:
Builder builde=new AlertDialog.Builder(this);
calendear=Calendar.getInstance();
dialog=new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// TODO Auto-generated method stub
tv.setText("您设置的时间为:"+hourOfDay+"点"+minute+"分");
}
}, calendear.get(Calendar.HOUR_OF_DAY), calendear.get(Calendar.MINUTE), true);
dialog=builde.create();
break;
default:
break;
}
return dialog;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
super.onCreate(savedInstanceState);
tv=(TextView)findViewById(R.id.textView1);
btn=(Button)findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
@SuppressWarnings("deprecation")
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
showDialog(MYDIALOG);
}
});
} 展开
1个回答
2014-01-23
展开全部
dialog=builde.create();这句话去掉
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询