無論DatePicker
也不TimePicker
對話框開放,當我做水龍頭上RelativeLayout
而調用相應的對話框我使用android:onClick="setDate"
和android:onClick="setTime"
的DatePicker和TimePicker對話問題
TimePicker
// On clicking Time picker
public void setTime(View v) {
Calendar mcurrentTime = Calendar.getInstance();
int hour = mcurrentTime.get(Calendar.HOUR_OF_DAY);
int minute = mcurrentTime.get(Calendar.MINUTE);
TimePickerDialog mTimePicker;
mTimePicker = new TimePickerDialog(getApplicationContext(), new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
mHour = selectedHour;
mMinute = selectedMinute;
if (selectedMinute < 10) {
mTime = selectedHour + ":" + "0" + selectedMinute;
} else {
mTime = selectedHour + ":" + selectedMinute;
}
mTimeText.setText(mTime);
}
}, hour, minute, false); // Is 24 hour time
}
的DatePicker
// On clicking Date picker
public void setDate(View v) {
Calendar mcurrentTime = Calendar.getInstance();
final int yearr = mcurrentTime.get(Calendar.YEAR);
final int month = mcurrentTime.get(Calendar.MONTH);
final int day_of_month = mcurrentTime.get(Calendar.DAY_OF_MONTH);
DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
monthOfYear++;
mDay = dayOfMonth;
mMonth = monthOfYear;
mYear = year;
mDate = day_of_month + "/" + month + "/" + yearr;
mDateText.setText(mDate);
}
};
}
我肯定壩,我有missed
東西上述功能
正如你可以看到下面,我也是在點擊使用這些功能:
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:clickable="true"
android:onClick="setDate"
android:id="@+id/date">
<ImageView
android:id="@+id/date_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="wrap_content"
android:orientation="vertical"
android:layout_toRightOf="@id/date_icon"
android:layout_height="wrap_content">
<TextView
android:id="@+id/date_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/date" />
<TextView
android:layout_width="wrap_content"
android:id="@+id/set_date"
android:layout_height="wrap_content"/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:clickable="true"
android:onClick="setTime"
android:id="@+id/time">
<ImageView
android:id="@+id/time_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="wrap_content"
android:orientation="vertical"
android:layout_toRightOf="@id/time_icon"
android:layout_height="wrap_content">
<TextView
android:id="@+id/time_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/time" />
<TextView
android:layout_width="wrap_content"
android:id="@+id/set_time"
android:layout_height="wrap_content"/>
</LinearLayout>
</RelativeLayout>
在tap方法中添加edittext的代碼 –
editext代碼?? –
沒有意思downvote this .... – Oreo