Skip to main content
5 de 7
se añadieron 4361 caracteres en el cuerpo

Marcar múltiples días DatePickerDialog

necesito hacer una selección de múltiples días en un DatePicker. Ya he conseguido guardar el valor de los días clicados, pero no consigo que se queden marcados en el DatePicker aquellos días que he seleccionado. Gracias

public class DataPickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener{
ArrayList<DatePicker> array = new ArrayList<DatePicker>();
DatePickerDialog t;
View p;
Drawable drawable;
DataPickerFragment yo;
TextView text;
Hashtable<String, String> datesselected;
ArrayList<View> arr;
int month;
int year;
int day;
private Object callback;
private static float BOTTOM_DATES = 200;
//private OnDayClickListener c;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState){
    //Use the current time as the default values for the time picker
    final Calendar c = Calendar.getInstance();
    if( callback instanceof UserForm) {
        c.add(java.util.Calendar.MONTH, 0);
        c.set(java.util.Calendar.DAY_OF_MONTH, 1);
        c.set(Calendar.YEAR, c.get(Calendar.YEAR) - 20);
    }
        day = c.get(Calendar.DAY_OF_MONTH);
        month = c.get(Calendar.MONTH);
        year = c.get(Calendar.YEAR);
    datesselected = new Hashtable<String, String>();
    Resources res = getResources();
    BOTTOM_DATES = res.getDimension(R.dimen.botom_dates);
    arr = new ArrayList<View>();



    t = new DatePickerDialog(getActivity(),this, day, month,year);
    LayoutInflater li = LayoutInflater.from(t.getContext());
    p = li.inflate(R.layout.pincho, null);
    p.setY(BOTTOM_DATES);
    text = (TextView) p.findViewById(R.id.textView2);
    text.setMovementMethod(new ScrollingMovementMethod());
    //t.getDatePicker().getOnFocusChangeListener().onFocusChange();

    t.setOnShowListener(new DialogInterface.OnShowListener(){

        @Override
        public void onShow(DialogInterface dialog) {
            if( callback instanceof CreateEvent) {
                t.addContentView(p, new LinearLayout.LayoutParams(t.getDatePicker().getWidth(), t.getDatePicker().getWidth() / 6));
                datesselected = ((CreateEvent)callback).getTablaHash();
                String dates = "";
                Enumeration keys = datesselected.keys();
                while (keys.hasMoreElements()) {
                    Object key = keys.nextElement();
                    dates += datesselected.get(key).toString() + "\n";
                }
                text.setText(dates);
            }
        }
    });
    t.getDatePicker().init(year,month,day, new DatePicker.OnDateChangedListener(){

        @Override
        public void onDateChanged(DatePicker view, int years, int monthOfYear, int dayOfMonth) {
            if(years != year){
                month = monthOfYear+1;
                year = years;
                day = dayOfMonth;
            }else {
                month = monthOfYear+1;
                year = years;
                day = dayOfMonth;
                if (datesselected.containsKey(dayOfMonth + "-" + monthOfYear + "-" + years)) {
                    datesselected.remove(dayOfMonth + "-" + monthOfYear + "-" + years);
                } else {
                    datesselected.put(dayOfMonth + "-" + monthOfYear + "-" + years, dayOfMonth + "-" + month + "-" + years);
                }
                String dates = "";
                Enumeration keys = datesselected.keys();
                while (keys.hasMoreElements()) {
                    Object key = keys.nextElement();
                    dates += datesselected.get(key).toString() + "\n";
                }

                text.setText(dates);
            }

        }

    });

    return t;
}



public void setCallback(CreateEvent callback){
    this.callback = callback;
}
public void setCallback(UserForm callback){
    this.callback = callback;
}
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
    if( callback instanceof CreateEvent) {
        ((CreateEvent)callback).setTablaHash(datesselected);
    }else{
        ((UserForm)callback).setDate(year, monthOfYear, dayOfMonth);
    }
}

}