Skip to content

Commit 2d488dd

Browse files
committed
修复timePicker 隐藏标签无效问题
1 parent 3a00892 commit 2d488dd

File tree

5 files changed

+45
-33
lines changed

5 files changed

+45
-33
lines changed

app/src/main/java/com/bigkoo/pickerviewdemo/MainActivity.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void onClick(View v) {
7676
private void initTimePicker() {
7777
//控制时间范围(如果不设置范围,则使用默认时间1900-2100年,此段代码可注释)
7878
Calendar selectedDate = Calendar.getInstance();
79-
selectedDate.set(2013,2,29);
79+
/* selectedDate.set(2013,2,29);*/
8080
Calendar startDate = Calendar.getInstance();
8181
startDate.set(2013,1,23);
8282
Calendar endDate = Calendar.getInstance();
@@ -94,10 +94,8 @@ public void onTimeSelect(Date date, View v) {//选中事件回调
9494
.setContentSize(18)
9595
.setTitleSize(20)
9696
.setTitleText("Title")
97-
9897
.isCyclic(true)// default is false
9998
.setTitleColor(Color.BLACK)
100-
.setDate(new Date())// default system*/
10199
/*.setDividerColor(Color.WHITE)//设置分割线的颜色
102100
.setTextColorCenter(Color.LTGRAY)//设置选中项的颜色
103101
.setLineSpacingMultiplier(1.6f)//设置两横线之间的间隔倍数
@@ -106,19 +104,18 @@ public void onTimeSelect(Date date, View v) {//选中事件回调
106104
.setSubmitColor(Color.WHITE)
107105
.setCancelColor(Color.WHITE)*/
108106
/* .gravity(Gravity.RIGHT)// default is center*/
107+
.setLabel("", "", "", "", "", "") //设置空字符串以隐藏单位提示 hide label
109108
.isDialog(false)
110109
.setOutSideCancelable(true)// default is true
111110
.setDividerColor(Color.BLACK)
112111
.setContentSize(20)
113-
.setLabel("", "", "", "", "", "") //设置空字符串以隐藏单位提示 hide label
114112
.setDate(selectedDate)
115113
.setRangDate(startDate,endDate)
116114
.build();
117115
}
118116

119117
private void initCustomTimePicker() {
120118
// 注意:自定义布局中,id为 optionspicker 或者 timepicker 的布局以及其子控件必须要有,否则会报空指针
121-
// 否则会报空指针
122119
// 具体可参考demo 里面的两个自定义布局
123120

124121
//控制时间范围(如果不设置范围,则使用默认时间1900-2100年,此段代码可注释)
@@ -362,8 +359,6 @@ public void onClick(View v) {
362359

363360
}
364361
})
365-
.setContentTextSize(20)
366-
.setDividerColor(Color.BLACK)
367362
.build();
368363
pvCustomOptions.setPicker(cardItem);//添加数据
369364

pickerview/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ android {
1111
defaultConfig {
1212
minSdkVersion 9
1313
targetSdkVersion 25
14-
versionCode 13
15-
versionName "3.0.9"
14+
versionCode 14
15+
versionName "3.1.0"
1616
}
1717
buildTypes {
1818
release {
@@ -38,7 +38,7 @@ publish {
3838
userOrg = 'contrarywind'//bintray.com 用户名/组织名 user/org name
3939
groupId = 'com.contrarywind'//JCenter上显示的路径 path
4040
artifactId = 'Android-PickerView'//项目名称 project name
41-
publishVersion = '3.0.9'//版本号 version code
41+
publishVersion = '3.1.0'//版本号 version code
4242
desc = 'this is a pickerview for android'//项目描述 description
4343
website = 'https://github.com/Contrarywind/Android-PickerView' //项目网址链接 link
4444
}

pickerview/src/main/java/com/bigkoo/pickerview/TimePickerView.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ private void initView(Context context) {
408408

409409
setTime();
410410
wheelTime.setLabels(label_year, label_month, label_day, label_hours, label_mins, label_seconds);
411+
411412
setOutSideCancelable(cancelable);
412413
wheelTime.setCyclic(cyclic);
413414
wheelTime.setDividerColor(dividerColor);
@@ -480,14 +481,12 @@ private void setTime() {
480481
seconds = date.get(Calendar.SECOND);
481482
}
482483

483-
/*System.out.println("month:" + month);
484-
System.out.println("day:" + day);
485-
System.out.println("year:" + year);*/
486-
487484
wheelTime.setPicker(year, month, day, hours, minute, seconds);
488485
}
489486

490487

488+
489+
491490
@Override
492491
public void onClick(View v) {
493492
String tag = (String) v.getTag();

pickerview/src/main/java/com/bigkoo/pickerview/view/WheelTime.java

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import java.text.SimpleDateFormat;
1414
import java.util.Arrays;
1515
import java.util.Calendar;
16-
import java.util.Date;
1716
import java.util.List;
1817

1918

@@ -89,7 +88,7 @@ public void setPicker(int year, final int month, int day, int h, int m, int s) {
8988
// 年
9089
wv_year = (WheelView) view.findViewById(R.id.year);
9190
wv_year.setAdapter(new NumericWheelAdapter(startYear, endYear));// 设置"年"的显示数据
92-
wv_year.setLabel(context.getString(R.string.pickerview_year));// 添加文字
91+
/*wv_year.setLabel(context.getString(R.string.pickerview_year));// 添加文字*/
9392
wv_year.setCurrentItem(year - startYear);// 初始化时显示的数据
9493
wv_year.setGravity(gravity);
9594
// 月
@@ -108,7 +107,7 @@ public void setPicker(int year, final int month, int day, int h, int m, int s) {
108107
wv_month.setAdapter(new NumericWheelAdapter(1, 12));
109108
wv_month.setCurrentItem(month);
110109
}
111-
wv_month.setLabel(context.getString(R.string.pickerview_month));
110+
/* wv_month.setLabel(context.getString(R.string.pickerview_month));*/
112111

113112
wv_month.setGravity(gravity);
114113
// 日
@@ -208,25 +207,25 @@ public void setPicker(int year, final int month, int day, int h, int m, int s) {
208207
wv_day.setCurrentItem(day - 1);
209208
}
210209

211-
wv_day.setLabel(context.getString(R.string.pickerview_day));
210+
/* wv_day.setLabel(context.getString(R.string.pickerview_day));*/
212211

213212
wv_day.setGravity(gravity);
214213
//时
215214
wv_hours = (WheelView) view.findViewById(R.id.hour);
216215
wv_hours.setAdapter(new NumericWheelAdapter(0, 23));
217-
wv_hours.setLabel(context.getString(R.string.pickerview_hours));// 添加文字
216+
/* wv_hours.setLabel(context.getString(R.string.pickerview_hours));// 添加文字*/
218217
wv_hours.setCurrentItem(h);
219218
wv_hours.setGravity(gravity);
220219
//分
221220
wv_mins = (WheelView) view.findViewById(R.id.min);
222221
wv_mins.setAdapter(new NumericWheelAdapter(0, 59));
223-
wv_mins.setLabel(context.getString(R.string.pickerview_minutes));// 添加文字
222+
/* wv_mins.setLabel(context.getString(R.string.pickerview_minutes));// 添加文字*/
224223
wv_mins.setCurrentItem(m);
225224
wv_mins.setGravity(gravity);
226225
//秒
227226
wv_seconds = (WheelView) view.findViewById(R.id.second);
228227
wv_seconds.setAdapter(new NumericWheelAdapter(0, 59));
229-
wv_seconds.setLabel(context.getString(R.string.pickerview_seconds));// 添加文字
228+
/* wv_seconds.setLabel(context.getString(R.string.pickerview_seconds));// 添加文字*/
230229
wv_seconds.setCurrentItem(s);
231230
wv_seconds.setGravity(gravity);
232231

@@ -492,18 +491,37 @@ private void setLineSpacingMultiplier() {
492491
}
493492

494493
public void setLabels(String label_year, String label_month, String label_day, String label_hours, String label_mins, String label_seconds) {
495-
if (label_year != null)
494+
if (label_year!=null){
496495
wv_year.setLabel(label_year);
497-
if (label_month != null)
496+
} else {
497+
wv_year.setLabel(view.getContext().getString(R.string.pickerview_year));
498+
}
499+
if (label_month!=null){
498500
wv_month.setLabel(label_month);
499-
if (label_day != null)
501+
} else {
502+
wv_month.setLabel(view.getContext().getString(R.string.pickerview_month));
503+
}
504+
if (label_day!=null){
500505
wv_day.setLabel(label_day);
501-
if (label_hours != null)
506+
}else {
507+
wv_day.setLabel(view.getContext().getString(R.string.pickerview_day));
508+
}
509+
if (label_hours!=null){
502510
wv_hours.setLabel(label_hours);
503-
if (label_mins != null)
511+
} else {
512+
wv_hours.setLabel(view.getContext().getString(R.string.pickerview_hours));
513+
}
514+
if (label_mins!=null){
504515
wv_mins.setLabel(label_mins);
505-
if (label_seconds != null)
516+
}else {
517+
wv_mins.setLabel(view.getContext().getString(R.string.pickerview_minutes));
518+
}
519+
if (label_seconds!=null){
506520
wv_seconds.setLabel(label_seconds);
521+
}else {
522+
wv_seconds.setLabel(view.getContext().getString(R.string.pickerview_seconds));
523+
}
524+
507525
}
508526

509527

pickerview/src/main/res/values-en/strings.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
<string name="pickerview_cancel">Cancel</string>
44
<string name="pickerview_submit">Sure</string>
5-
<string name="pickerview_year">Y</string>
6-
<string name="pickerview_month">M</string>
7-
<string name="pickerview_day">D</string>
8-
<string name="pickerview_hours">h</string>
9-
<string name="pickerview_minutes">m</string>
10-
<string name="pickerview_seconds">s</string>
5+
<string name="pickerview_year"></string>
6+
<string name="pickerview_month"></string>
7+
<string name="pickerview_day"></string>
8+
<string name="pickerview_hours"></string>
9+
<string name="pickerview_minutes"></string>
10+
<string name="pickerview_seconds"></string>
1111
</resources>

0 commit comments

Comments
 (0)