Android:使用android wheel widget设置时间

时间:2013-03-12 06:04:01

标签: android

我正在使用kankans用于Android的滚轮小部件,如下所示

ImageView setTime = (ImageView) dialog.findViewById(R.id.autodelete);
                setTime.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        final Calendar c = Calendar.getInstance();
                        int hour = c.get(Calendar.HOUR_OF_DAY);
                        int minute = c.get(Calendar.MINUTE);
                        SetTime(activity, hour, minute);
                    }
                });

    private void SetTime(Context activity, int hour, int minute) {

            LayoutInflater inf = LayoutInflater.from(activity);

            View view = inf.inflate(R.layout.wheel, null);

            final WheelView hours = (WheelView) view.findViewById(R.id.hours);
            hours.setViewAdapter(new NumericWheelAdapter(activity, 0, 23,"%02d"));
            hours.setCyclic(true);


            final WheelView mins = (WheelView) view.findViewById(R.id.minutes);
            mins.setViewAdapter(new Mywheel(activity, 0, 59,"%02d"));
            mins.setCyclic(true);

            new AlertDialog.Builder(activity)
                    .setMessage("Set Time For Post To AutoDelete")
                    .setView(view)
                    .setPositiveButton("Set",
                            new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {

                                    expiryHour = hours.getCurrentItem();
                                                                        if(mins.getCurrentItem() > 0){
                                             expiryMinute = mins.getCurrentItem() + 4;
                                                                        }else{
                                             expiryMinute = mins.getCurrentItem();
                                                                        }
                                }
                            })
                    .setNegativeButton("Cancel",
                            new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog,
                                        int which) {
                                    return;
                                }
                            }).create().show();

        }

当我打开并设置时间时,我得到了我设置的正确值。问题是在设置时间后再次打开对话框应显示我设置的上一个值,但它显示从00开始。任何帮助表示赞赏

0 个答案:

没有答案