Bigkoo / Android-PickerView

This is a picker view for android , support linkage effect, timepicker and optionspicker.(时间选择器、省市区三级联动)
Apache License 2.0
13.45k stars 3.45k forks source link

本人菜鸟。多点几次就崩溃了。 #605

Closed lxfwelldone closed 6 years ago

lxfwelldone commented 6 years ago

我在自定义布局中添加了,三个日期按钮,日,月,年,来控制显示:年月日,年月,年。 然后点击一个日期按钮,选择时间,点击确定按钮。再弹出时间选择器,点击另一个日期按钮,选择时间,点击确定按钮,操作几次后,点击确定按钮时,就奔溃了。请问怎么解决?

xml 布局文件

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:layout_margin="10dp"
    android:paddingBottom="4dp"
    android:paddingTop="4dp"
    >
      <TextView 
        android:layout_width="0dp"
        android:layout_height="32dp"
        android:layout_weight="1"
        android:text="日"
        android:background="@drawable/fragment_left_my"
        android:gravity="center"  
        android:textSize="16sp"  
        android:textColor="#ffffff"
        android:id="@+id/tv_day"                
        />

    <TextView 
        android:layout_width="0dp"
        android:layout_height="32dp"
        android:layout_weight="1"
        android:text="月"
        android:background="@drawable/fragment_center_my"
        android:gravity="center"   
        android:textSize="16sp"  
        android:id="@+id/tv_month"

        />

    <TextView 
        android:layout_width="0dp"
        android:layout_height="32dp"
        android:layout_weight="1"
        android:text="年"
        android:background="@drawable/fragment_right_my"
        android:gravity="center"
        android:textSize="16sp"  
        android:id="@+id/tv_year"
        />

</LinearLayout>

<LinearLayout
    android:id="@+id/timepicker"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white"
    android:orientation="horizontal">

    <com.contrarywind.view.WheelView
        android:id="@+id/year"
        android:layout_width="fill_parent"
        android:layout_height="32dp"
        android:layout_weight="1" />

    <com.contrarywind.view.WheelView

        android:id="@+id/month"
        android:layout_width="fill_parent"
        android:layout_height="32dp"
        android:layout_weight="1.1" />

    <com.contrarywind.view.WheelView
        android:id="@+id/day"
        android:layout_width="fill_parent"
        android:layout_height="32dp"
        android:layout_weight="1.1" />

    <com.contrarywind.view.WheelView
        android:id="@+id/hour"
        android:layout_width="fill_parent"
        android:layout_height="32dp"
        android:layout_weight="1.1" />

    <com.contrarywind.view.WheelView
        android:id="@+id/min"
        android:layout_width="fill_parent"
        android:layout_height="32dp"
        android:layout_weight="1.1" />

    <com.contrarywind.view.WheelView
        android:id="@+id/second"
        android:layout_width="fill_parent"
        android:layout_height="32dp"
        android:layout_weight="1.1" />
</LinearLayout>

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:paddingTop="12dp"
    android:paddingBottom="12dp"
    android:text="确定"
    android:textColor="#ffffff"    
    android:background="@color/operation_navigation"  
    android:gravity="center"
    android:textSize="16sp"
    android:id="@+id/tv_ok"
    />       

//时间选择器 ,自定义布局

    pvCustomTime = new TimePickerBuilder(this, new OnTimeSelectListener() {
        @Override
        public void onTimeSelect(Date date, View v) {
            dateSelected = date;
            cashierReportService.list(requestType, CommonUtils.formatDate(date), payTypeSn);
        }
    }) .setDate(selectedDate)
            .setLayoutRes(R.layout.pickerview_my_datepicker, new CustomListener() {

                @Override
                public void customLayout(View v) {

                    final TextView tv_year = (TextView) v.findViewById(R.id.tv_year);
                    final TextView tv_month = (TextView) v.findViewById(R.id.tv_month);
                    final TextView tv_day = (TextView) v.findViewById(R.id.tv_day);

                    tv_day.setSelected(true);
                    tv_year.setOnClickListener(new OnClickListener() {                          
                        @Override
                        public void onClick(View v) {
                            if (v.isSelected()) {
                                return;
                            }
                            requestType = "y";

                            tv_year.setSelected(true);
                            tv_year.setTextColor(Color.WHITE);
                            tv_month.setSelected(false);
                            tv_month.setTextColor(Color.BLACK);
                            tv_day.setSelected(false);
                            tv_day.setTextColor(Color.BLACK);
                            pvCustomTime.findViewById(R.id.year).setVisibility(View.VISIBLE);
                            pvCustomTime.findViewById(R.id.month).setVisibility(View.GONE);
                            pvCustomTime.findViewById(R.id.day).setVisibility(View.GONE);
                        }
                    });
                    tv_month.setOnClickListener(new OnClickListener() {                         
                        @Override
                        public void onClick(View v) {
                            if (v.isSelected()) {
                                return;
                            }
                            requestType = "m";

                            tv_year.setSelected(false);
                            tv_year.setTextColor(Color.BLACK);
                            tv_month.setSelected(true);
                            tv_month.setTextColor(Color.WHITE);
                            tv_day.setSelected(false);
                            tv_day.setTextColor(Color.BLACK);

                            pvCustomTime.findViewById(R.id.year).setVisibility(View.VISIBLE);
                            pvCustomTime.findViewById(R.id.month).setVisibility(View.VISIBLE);
                            pvCustomTime.findViewById(R.id.day).setVisibility(View.GONE);
                        }
                    });
                    tv_day.setOnClickListener(new OnClickListener() {                           
                        @Override
                        public void onClick(View v) {
                            if (v.isSelected()) {
                                return;
                            }
                            requestType = "d";

                            tv_year.setSelected(false);
                            tv_year.setTextColor(Color.BLACK);
                            tv_month.setSelected(false);
                            tv_month.setTextColor(Color.BLACK);
                            tv_day.setSelected(true);
                            tv_day.setTextColor(Color.WHITE);
                            pvCustomTime.findViewById(R.id.year).setVisibility(View.VISIBLE);
                            pvCustomTime.findViewById(R.id.month).setVisibility(View.VISIBLE);
                            pvCustomTime.findViewById(R.id.day).setVisibility(View.VISIBLE);
                        }
                    });
                    final TextView tv_OK = (TextView) v.findViewById(R.id.tv_ok);
                    tv_OK.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            pvCustomTime.dismiss();
                            pvCustomTime.returnData();
                        }
                    });
                }
            })
            .setContentTextSize(18)
            .setType(shows)
            .setLabel("年", "月", "日", "时", "分", "秒")
            .setLineSpacingMultiplier(1.8f)
            .setTextXOffset(0, 0, 0, 40, 0, -40)
            .isCenterLabel(false) 
            .setDividerColor(0xFF24AD9D)
            .build();
}
lxfwelldone commented 6 years ago

发现问题并不是这个时间选择导致的。尴尬了。。。

saiwu-bigkoo commented 6 years ago

(= =) 好的。