将手势添加到自定义日期时间选择器android

时间:2014-01-31 06:40:37

标签: android datepicker gesture android-timepicker

我想在我的自定义日期时间选择器上添加手势onDown和onflig如果有人知道请建议。我粘贴下面的图片请检查并建议。

enter image description here

目前我正在使用点击监听器更改日期和时间

 View.OnClickListener hour_plus_listener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            hour_display.requestFocus();

            try { 
                    cal.add(Calendar.HOUR_OF_DAY, 1); 
                sendToDisplay();
            } catch (Exception e) {
                Log.e("", e.toString());

            }
        }
    };
    View.OnClickListener hour_minus_listener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            hour_display.requestFocus();

            try {  
                    cal.add(Calendar.HOUR_OF_DAY, -1); 
                sendToDisplay();
            } catch (Exception e) {
                Log.e("", e.toString());
            }
        }
    };

    View.OnClickListener min_plus_listener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            min_display.requestFocus();

            try {
                cal.add(Calendar.MINUTE, 1);
                sendToDisplay();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    View.OnClickListener min_minus_listener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            min_display.requestFocus();

            try {
                cal.add(Calendar.MINUTE, -1);
                sendToDisplay();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };

    String[] months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
            "Sep", "Oct", "Nov", "Dec" };

    View.OnClickListener month_plus_listener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            try {
                cal.add(Calendar.MONTH, 1);

                month_display.setText(months[cal.get(Calendar.MONTH)]);
                year_display.setText(String.valueOf(cal.get(Calendar.YEAR)));
                date_display.setText(String.valueOf(cal
                        .get(Calendar.DAY_OF_MONTH)));

                changeFilter();
                sendToListener();
            } catch (Exception e) {
                Log.e("", e.toString());
            }
        }
    };
    View.OnClickListener month_minus_listener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                cal.add(Calendar.MONTH, -1);

                month_display.setText(months[cal.get(Calendar.MONTH)]);
                year_display.setText(String.valueOf(cal.get(Calendar.YEAR)));
                date_display.setText(String.valueOf(cal
                        .get(Calendar.DAY_OF_MONTH)));

                changeFilter();
                sendToListener();
            } catch (Exception e) {
                Log.e("", e.toString());
            }
        }
    };
    View.OnClickListener date_plus_listener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            try {
                date_display.requestFocus();
                cal.add(Calendar.DAY_OF_MONTH, 1);

                month_display.setText(months[cal.get(Calendar.MONTH)]);
                year_display.setText(String.valueOf(cal.get(Calendar.YEAR)));
                date_display.setText(String.valueOf(cal
                        .get(Calendar.DAY_OF_MONTH)));

                sendToListener();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    };
    View.OnClickListener date_minus_listener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            try {
                date_display.requestFocus();
                cal.add(Calendar.DAY_OF_MONTH, -1);

                month_display.setText(months[cal.get(Calendar.MONTH)]);
                year_display.setText(String.valueOf(cal.get(Calendar.YEAR)));
                date_display.setText(String.valueOf(cal
                        .get(Calendar.DAY_OF_MONTH)));

                sendToListener();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    };
    View.OnClickListener year_plus_listener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            try {
                year_display.requestFocus();

                if (cal.get(Calendar.YEAR) >= endYear) {

                    cal.set(Calendar.YEAR, startYear);

                } else {
                    cal.add(Calendar.YEAR, +1);

                }

                month_display.setText(months[cal.get(Calendar.MONTH)]);
                year_display.setText(String.valueOf(cal.get(Calendar.YEAR)));
                date_display.setText(String.valueOf(cal
                        .get(Calendar.DAY_OF_MONTH)));

                changeFilter();
                sendToListener();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    };
    View.OnClickListener year_minus_listener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            try {
                year_display.requestFocus();

                if (cal.get(Calendar.YEAR) <= startYear) {
                    cal.set(Calendar.YEAR, endYear);

                } else {
                    cal.add(Calendar.YEAR, -1);

                }

                month_display.setText(months[cal.get(Calendar.MONTH)]);
                year_display.setText(String.valueOf(cal.get(Calendar.YEAR)));
                date_display.setText(String.valueOf(cal
                        .get(Calendar.DAY_OF_MONTH)));

                changeFilter();
                sendToListener();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    };

0 个答案:

没有答案