3

i managed to get a custom DatePicker and add it to my project , the problem is , that when i tape Twice on a date , the application crashes !

custom datePicker code :

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;
    }

}

and this is how i used that class in my main activity :

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)
AbdallahJg
  • 69
  • 7

1 Answers1

1

It is a problem with specific devices

to log or prompt for selected date, DatePicker uses

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

but for some reason it gets "%d selected" and format date is not an integer.

See this answer: https://stackoverflow.com/a/31855744/848072. It proposes a patch. Using a theme that do not look for an incorrect resource, leading to a format error.

Maybe there will be no patch for these so, use the workaround meanwhile

Community
  • 1
  • 1
albfan
  • 12,542
  • 4
  • 61
  • 80