Iam使用Material Design Datepicker我可以从明天开始设置,但是今天的日期也会在日历i set for 29/11/2016 but it also showing 28/11/2016中显示 如何禁用它以便用户无法选择它 我使用Material Design DatePicker https://github.com/wdullaer/MaterialDateTimePicker
GregorianCalendar g1=new GregorianCalendar();
g1.add(Calendar.DATE, 1);
GregorianCalendar gc = new GregorianCalendar();
gc.add(Calendar.DAY_OF_MONTH, 30);
dateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
DatePickerDialog datePickerDialog ;
datePickerDialog = DatePickerDialog.newInstance(LoginSuccess.this, g1.get(Calendar.YEAR),
g1.get(Calendar.MONTH),
g1.get(Calendar.DAY_OF_MONTH));
datePickerDialog.setTitle("Select Date");
//datePickerDialog.setMinDate(g);
GregorianCalendar c2=new GregorianCalendar();
c2.setTimeInMillis(g1.getTimeInMillis()+(27*7*24*60*60*1000));
//c2.add(Calendar.DAY_OF_MONTH, 30);
List<Calendar> dayslist= new LinkedList<Calendar>();
Calendar[] daysArray;
Calendar cAux = Calendar.getInstance();
while ( cAux.getTimeInMillis() <= gc.getTimeInMillis())
{
if (cAux.get(Calendar.DAY_OF_WEEK)!=1)
{
Calendar c = Calendar.getInstance();
c.setTimeInMillis(cAux.getTimeInMillis());
dayslist.add(c);
}
cAux.setTimeInMillis(cAux.getTimeInMillis()+(24*60*60*1000));
}
daysArray = new Calendar[dayslist.size()];
for (int i = 0; i<daysArray.length;i++)
{
daysArray[i]=dayslist.get(i);
}
//g1.setTimeInMillis(g.getTimeInMillis()+(7*24*60*60*1000));
datePickerDialog.setMinDate(g1);
datePickerDialog.setMaxDate(c2);
datePickerDialog.show(getFragmentManager(), "DatePickerDialog");
datePickerDialog.setSelectableDays(daysArray);
}
答案 0 :(得分:1)
试试这个!
dateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Calendar now = Calendar.getInstance();
now.add(Calendar.DAY_OF_YEAR, 1);
DatePickerDialog dpd = DatePickerDialog.newInstance(
MainActivity.this,
now.get(Calendar.YEAR),
now.get(Calendar.MONTH),
now.get(Calendar.DAY_OF_MONTH)
);
dpd.setMinDate(now);
dpd.setThemeDark(modeDarkDate.isChecked());
dpd.vibrate(vibrateDate.isChecked());
dpd.dismissOnPause(dismissDate.isChecked());
dpd.showYearPickerFirst(showYearFirst.isChecked());
if (modeCustomAccentDate.isChecked()) {
dpd.setAccentColor(Color.parseColor("#9C27B0"));
}
if(titleDate.isChecked()) {
dpd.setTitle("DatePicker Title");
}
dpd.show(getFragmentManager(), "Datepickerdialog");
}
});
}
答案 1 :(得分:1)
嘿,我已经完成了关于这个问题的样本,并且能够按照您的预期获得日期选择器一旦检查并让我知道 爪哇:
from tkinter import *
import random
class Window(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master = master
self.init_window()
def init_window(self):
self.pack(fill=BOTH, expand=1)
testButton = Button(self, text="Press",
command=lambda win=self: calc(win))
testButton.pack()
self.l1 = Label(text="")
self.l1.pack()
def testbutton(self, ans):
self.l1.configure(text=ans)
def calc(window): # note window argument added
list1 = ["a","b","c"]
index = random.randint(0,2)
answer = list1[index]
window.testbutton(answer)
root = Tk()
root.geometry("400x300")
app = Window(root)
root.mainloop()
}
布局:
package yourpackage;
import java.util.Calendar;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
private DatePicker datePicker;
private Calendar calendar;
private TextView dateView;
private int year, month, day;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
dateView = (TextView) findViewById(R.id.textView3);
calendar = Calendar.getInstance();
year = calendar.get(Calendar.YEAR);
month = calendar.get(Calendar.MONTH);
day = calendar.get(Calendar.DAY_OF_MONTH);
showDate(year, month + 1, day);
}
@SuppressWarnings("deprecation")
public void setDate(View view) {
showDialog(1);
Toast.makeText(getApplicationContext(), "ca", Toast.LENGTH_SHORT)
.show();
}
@Override
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
if (id == 1) {
return new DatePickerDialog(this, myDateListener, year, month,
day + 1);
}
return null;
}
private DatePickerDialog.OnDateSetListener myDateListener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
// arg1 = year
// arg2 = month
// arg3 = day
showDate(arg1, arg2 + 1, arg3);
}
};
private void showDate(int year, int month, int day) {
dateView.setText(new StringBuilder().append(day).append("/")
.append(month).append("/").append(year));
}
值
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="70dp"
android:onClick="setDate"
android:text="@string/date_button_set" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:text="@string/date_label_set"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button1"
android:layout_marginTop="66dp"
android:layout_toLeftOf="@+id/button1"
android:text="@string/date_view_set"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/button1"
android:layout_below="@+id/textView2"
android:layout_marginTop="72dp"
android:text="@string/date_selected"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
答案 2 :(得分:0)
java.lang.NoClassDefFoundError: Could not initialize class javax.crypto.JceSecurity
javax.crypto.KeyAgreement.getInstance(KeyAgreement.java:179)
sun.security.ssl.JsseJce.getKeyAgreement(JsseJce.java:286)
sun.security.ssl.JsseJce.isEcAvailable(JsseJce.java:199)
sun.security.ssl.CipherSuite$KeyExchange.isAvailable(CipherSuite.java:376)
sun.security.ssl.CipherSuite.isAvailable(CipherSuite.java:194)
sun.security.ssl.SSLContextImpl.getApplicableCipherSuiteList(SSLContextImpl.java:338)
sun.security.ssl.SSLContextImpl.getDefaultCipherSuiteList(SSLContextImpl.java:296)
sun.security.ssl.SSLSocketImpl.init(SSLSocketImpl.java:593)
sun.security.ssl.SSLSocketImpl.<init>(SSLSocketImpl.java:557)
sun.security.ssl.SSLSocketFactoryImpl.createSocket(SSLSocketFactoryImpl.java:109)
com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:361)
com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:236)
com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2020)
com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:697)
javax.mail.Service.connect(Service.java:364)
javax.mail.Service.connect(Service.java:245)
com.cvs.util.SendMail.sendAccountConfirmation(SendMail.java:54)
com.cvs.controller.SignUp.doPost(SignUp.java:121)
javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
像这样检查
答案 3 :(得分:0)
你应该这样做,
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH, day + 1);
cal.set(Calendar.MONTH, month);
cal.set(Calendar.YEAR, year);
datePickerDialog.getDatePicker().setMaxDate(maxDate.getTimeInMillis());
这将限制您选择当前日期并让您选择 日期从明天开始。
答案 4 :(得分:0)
从我记得的这个库的文档中,我相信如果你设置MaterialDateTimePicker的可选日期,那么它会覆盖你为最小和最大日期设置的任何事情。因此,如果您传递一系列日期,则需要包括您的最短和最长日期,以及您希望在其间查看的所有内容。