I want to add new button,which is clear button, to date picker widget and time picker widget in my android application. In default, these widgets have two button,set and cancel. How can I add one more button to these two button
Is it possible? If yes, can you give some example?
Thanks
Simply create this class!
import android.app.DatePickerDialog;
import android.content.Context;
public class DatePickerWithNeutral extends DatePickerDialog {
public DatePickerWithNeutral(Context context, OnDateSetListener callBack,
int year, int monthOfYear, int dayOfMonth) {
super(context, 0, callBack, year, monthOfYear, dayOfMonth);
setButton(BUTTON_POSITIVE, ("Ok"), this);
setButton(BUTTON_NEUTRAL, ("Something"), this); // ADD THIS
setButton(BUTTON_NEGATIVE, ("Cancel"), this);
}
}
Then use this to add functionality to it!
date.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "Neutral Button Clicked!",
Toast.LENGTH_LONG).show();
}
});
Looks like this
Enjoy :)
Just add a neutral button.
DatePickerDialog dialog = new DatePickerDialog(context, 0, callback, year, month, day);
dialog.setButton(DialogInterface.BUTTON_NEUTRAL, "Name", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//Your code
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With