当前位置: 代码迷 >> Android >> android中 dialog展示TimePickerDialog
  详细解决方案

android中 dialog展示TimePickerDialog

热度:44   发布时间:2016-05-01 15:35:34.0
android中 dialog显示TimePickerDialog
package com.dialog;import android.app.Activity;import android.app.Dialog;import android.app.TimePickerDialog;import android.os.Bundle;import android.widget.TimePicker;import android.widget.Toast;public class dialogdatetume extends Activity {	int hour, minute1;    static final int TIME_DIALOG_ID = 0;    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.datetimepicker);        showDialog(TIME_DIALOG_ID);    }	@Override	protected Dialog onCreateDialog(int id) {		// TODO Auto-generated method stub		//return super.onCreateDialog(id);		switch (id) {        case TIME_DIALOG_ID:             return new TimePickerDialog( this, mTimeSetListener, hour, minute1, false);    }    return null; 	}	   private TimePickerDialog.OnTimeSetListener mTimeSetListener =		    new TimePickerDialog.OnTimeSetListener() 	   {				@Override				public void onTimeSet(TimePicker view, int hourOfDay, int minute) {					// TODO Auto-generated method stub					 hour = hourOfDay;			           minute1 = minute;  			            Toast.makeText(getBaseContext(), 			                "You have selected : " + hour + ":" + minute1,			                Toast.LENGTH_SHORT).show();				}		    };}

?

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    >     <TimePicker        android:layout_width="wrap_content"        android:layout_height="wrap_content" />             </LinearLayout>

?

  相关解决方案