-
-
Notifications
You must be signed in to change notification settings - Fork 945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clear button. #183
Comments
What would you like to be cleared exactly? If you need to clear an alarm in your app, try adding it to your app UI with a seperate button, or a swipe to dismiss action |
Hi, thank you for your reply. I have a clickable text field, when user clicks on it date picker dialog shows up. Then user selects a date and date value sets to that textview. The problem is that I don't have a lot of space in that textview and clear button looks terrible there. Is there a way to add an extra button to datepicker dialog such as "Clear"? |
Check PR #156 |
FWIW, here is a way that you can add a "Clear" button (or any other button for that matter) into DatePickerDialog using version 2.2.0 of MaterialDateTimePicker. ClearableDatePickerDialog.java: public class ClearableDatePickerDialog extends DatePickerDialog {
private OnDateClearedListener mOnDateClearedListener;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle state) {
View view = super.onCreateView(inflater, container, state);
LinearLayout buttonContainer = (LinearLayout) view.findViewById(
com.wdullaer.materialdatetimepicker.R.id.done_background);
View clearButton = inflater.inflate(R.layout.date_picker_dialog_clear_button,
buttonContainer, false);
clearButton.setOnClickListener(new ClearClickListener());
buttonContainer.addView(clearButton, 0);
return view;
}
public void setOnDateClearedListener(OnDateClearedListener listener) {
mOnDateClearedListener = listener;
}
public OnDateClearedListener getOnDateClearedListener() {
return mOnDateClearedListener;
}
public interface OnDateClearedListener {
/**
* @param view The view associated with this listener.
*/
void onDateCleared(ClearableDatePickerDialog view);
}
private class ClearClickListener implements View.OnClickListener {
@Override
public void onClick(View view) {
tryVibrate();
OnDateClearedListener listener = getOnDateClearedListener();
if (listener != null) {
listener.onDateCleared(ClearableDatePickerDialog.this);
}
dismiss();
}
}
} date_picker_dialog_clear_button.xml: <?xml version="1.0" encoding="utf-8"?>
<!--
This button is based on
https://github.com/wdullaer/MaterialDateTimePicker/blob/master/library/src/main/res/layout/mdtp_done_button.xml
-->
<Button
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/clear"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
style="@style/mdtp_ActionButton.Text"
android:text="@string/clear"
/> |
Great stuff. It shows how you can extend this without me having to support a thousand different rarely used options :-) |
Is there any possiblity to remove all button..... just by clicking on date...Date will be set to your textview. |
The pickers extend |
in datepickerdialog show me this type error java.lang.RuntimeException: Font asset not found fonts/Roboto-Medium.ttf sometime please give me solution how to fix that? |
Can you please create a new issue, rather than commenting in totally unrelated ones? |
How to create new issue? |
Hi,
Is it possible to add a third button (clear) to date picker dialog?
Thank you
The text was updated successfully, but these errors were encountered: