当前位置: 首页 > 知识库问答 >
问题:

在DatePicker上双击时应用程序崩溃

卫深
2023-03-14

自定义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)

共有1个答案

戚星腾
2023-03-14

这是特定设备的问题

若要记录或提示所选日期,DatePicker使用

https://android.googlesource.com/platform/frameworks/opt/datetimepicker/+/master/res/values-es/strings.xml#29

 类似资料: