我设法得到一个自定义的DatePicker并将其添加到我的项目中,问题是,当我在某个日期粘贴两次时,应用程序崩溃了!
自定义datePicker代码:
package com.example.logindesign;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ViewParent;
import android.widget.CalendarView;
public class CalendarViewScrollable extends CalendarView {
public CalendarViewScrollable(Context context) {
super(context);
}
public CalendarViewScrollable(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CalendarViewScrollable(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev)
{
if (ev.getActionMasked() == MotionEvent.ACTION_DOWN)
{
ViewParent p = getParent();
if (p != null)
p.requestDisallowInterceptTouchEvent(true);
}
return false;
}
}
这就是我在主要活动中使用该课程的方式:
final TextView dateT=(TextView)findViewById(R.id.TextDate);
dateT.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
DatePickerDialog datepicker= new DatePickerDialog(MainActivity.this,new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month,
int day) {
// TO DO Auto-generated method stub
month+=1;
dateT.setText(+year + " / " + month + " / " + day);
jn=day;
mn=month;
an=year;
}
},1990,1,1);
datepicker.setTitle("Sélectionner la date de naissance");
datepicker.updateDate(1990, 1, 1);
datepicker.show();
}
});
Logcat:
04-28 20:02:39.504: E/AndroidRuntime(27825): FATAL EXCEPTION: main
04-28 20:02:39.504: E/AndroidRuntime(27825): Process: com.example.logindesign, PID: 27825
04-28 20:02:39.504: E/AndroidRuntime(27825): java.util.IllegalFormatConversionException: %d can't format java.lang.String arguments
04-28 20:02:39.504: E/AndroidRuntime(27825): at java.util.Formatter.badArgumentType(Formatter.java:1489)
04-28 20:02:39.504: E/AndroidRuntime(27825): at java.util.Formatter.transformFromInteger(Formatter.java:1689)
04-28 20:02:39.504: E/AndroidRuntime(27825): at java.util.Formatter.transform(Formatter.java:1461)
04-28 20:02:39.504: E/AndroidRuntime(27825): at java.util.Formatter.doFormat(Formatter.java:1081)
04-28 20:02:39.504: E/AndroidRuntime(27825): at java.util.Formatter.format(Formatter.java:1042)
04-28 20:02:39.504: E/AndroidRuntime(27825): at java.util.Formatter.format(Formatter.java:1011)
04-28 20:02:39.504: E/AndroidRuntime(27825): at java.lang.String.format(String.java:1803)
04-28 20:02:39.504: E/AndroidRuntime(27825): at android.content.res.Resources.getString(Resources.java:668)
04-28 20:02:39.504: E/AndroidRuntime(27825): at android.content.Context.getString(Context.java:390)
04-28 20:02:39.504: E/AndroidRuntime(27825): at android.widget.SimpleMonthView$MonthViewTouchHelper.getItemDescription(SimpleMonthView.java:683)
04-28 20:02:39.504: E/AndroidRuntime(27825): at android.widget.SimpleMonthView$MonthViewTouchHelper.onPopulateEventForVirtualVie w(SimpleMonthView.java:620)
04-28 20:02:39.504: E/AndroidRuntime(27825): at com.android.internal.widget.ExploreByTouchHelper.createEventForChild(ExploreByTo uchHelper.java:294)
答案 0 :(得分:-1)
特定设备存在问题
记录或提示选择日期,DatePicker使用
但由于某种原因,它会被“%d选中”,格式日期不是整数。
请参阅此答案:https://stackoverflow.com/a/31855744/848072。它提出了一个补丁。使用不查找不正确资源的主题,导致格式错误。
也许这些都没有补丁,请同时使用解决方法