Skip to content

Commit 043e1fc

Browse files
committed
新增多项选择
1 parent 2a4dc8b commit 043e1fc

11 files changed

Lines changed: 140 additions & 5 deletions

File tree

‎app/build.gradle‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ dependencies {
2626
compile project(':library:WheelPicker')
2727
compile project(':library:FilePicker')
2828
compile project(':library:ColorPicker')
29+
compile project(':library:MultiplePicker')
2930
// compile files('libs/AndroidPicker-1.5.2.jar')
3031
// compile 'cn.qqtheme.framework:WheelPicker:latest.release'
3132
// compile 'cn.qqtheme.framework:FilePicker:latest.release'

‎app/src/main/java/cn/qqtheme/androidpicker/MainActivity.java‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import cn.qqtheme.framework.picker.DoublePicker;
2828
import cn.qqtheme.framework.picker.FilePicker;
2929
import cn.qqtheme.framework.picker.LinkagePicker;
30+
import cn.qqtheme.framework.picker.MultiplePicker;
3031
import cn.qqtheme.framework.picker.NumberPicker;
3132
import cn.qqtheme.framework.picker.OptionPicker;
3233
import cn.qqtheme.framework.picker.TimePicker;
@@ -237,6 +238,7 @@ public void onDoublePicker(View view) {
237238
picker.setSelectedIndex(0, 0);
238239
picker.setFirstLabel("于", null);
239240
picker.setSecondLabel("骑/乘", "出发");
241+
picker.setTextSize(12);
240242
picker.setOnPickListener(new DoublePicker.OnPickListener() {
241243
@Override
242244
public void onPicked(int selectedFirstIndex, int selectedSecondIndex) {
@@ -246,6 +248,17 @@ public void onPicked(int selectedFirstIndex, int selectedSecondIndex) {
246248
picker.show();
247249
}
248250

251+
public void onMultiplePicker(View view) {
252+
MultiplePicker picker = new MultiplePicker(this, new String[]{"穿青人", "少数民族", "已识别民族", "未定民族"});
253+
picker.setOnItemPickListener(new MultiplePicker.OnItemPickListener() {
254+
@Override
255+
public void onItemPicked(int count, List<String> items) {
256+
showToast("已选" + count + "项:" + items);
257+
}
258+
});
259+
picker.show();
260+
}
261+
249262
public void onLinkagePicker(View view) {
250263
//联动选择器的更多用法,可参见AddressPicker和CarNumberPicker
251264
LinkagePicker.DataProvider provider = new LinkagePicker.DataProvider() {

‎app/src/main/res/layout/activity_main.xml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@
8484
android:onClick="onDoublePicker"
8585
android:text="双项选择"/>
8686

87+
<Button
88+
android:layout_width="match_parent"
89+
android:layout_height="wrap_content"
90+
android:onClick="onMultiplePicker"
91+
android:text="多项选择"/>
92+
93+
<Button
94+
android:layout_width="match_parent"
95+
android:layout_height="wrap_content"
96+
android:onClick="onDoublePicker"
97+
android:text="双项选择"/>
98+
8799
<Button
88100
android:layout_width="match_parent"
89101
android:layout_height="wrap_content"

‎build.gradle‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.1.2'
8+
classpath 'com.android.tools.build:gradle:2.3.3'
99
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
1010
}
1111
}

‎gradle.properties‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ com.android.build.gradle.overridePathCheck=true
1717
#下面定义一些常量供gradle脚本使用
1818
VERSION_NAME=1.5.2
1919
VERSION_CODE=152
20-
COMPILE_SDK_VERSION=23
20+
COMPILE_SDK_VERSION=25
2121
MIN_SDK_VERSION=14
2222
#安卓6.0开始(API23+),需要动态申请权限
2323
TARGET_SDK_VERSION=23
24-
BUILD_TOOL_VERSION=23.0.1
24+
BUILD_TOOL_VERSION=25.0.1
2525
ANDROID_SUPPORT_VERSION=latest.release
2626
GROUP=cn.qqtheme.framework
2727
SITE_URL=http://qqtheme.cn
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Fri Mar 03 00:22:35 CST 2017
1+
#Sat Jun 24 17:00:52 CST 2017
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

‎library/MultiplePicker/.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/build
2+
/*.iml
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apply plugin: 'com.android.library'
2+
3+
ext {
4+
isLibrary = true
5+
pomArtifactId = "MultiplePicker"
6+
pomDescription = "multiple picker for android"
7+
}
8+
9+
dependencies {
10+
compile project(":library:Common")
11+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="cn.qqtheme.framework.multiplepicker">
4+
5+
</manifest>
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package cn.qqtheme.framework.picker;
2+
3+
import android.app.Activity;
4+
import android.support.annotation.NonNull;
5+
import android.view.Gravity;
6+
import android.widget.CheckBox;
7+
import android.widget.LinearLayout;
8+
import android.widget.ScrollView;
9+
import android.widget.TextView;
10+
11+
import java.util.ArrayList;
12+
import java.util.Arrays;
13+
import java.util.List;
14+
15+
import cn.qqtheme.framework.popup.ConfirmPopup;
16+
17+
/**
18+
* 多项选择器
19+
*
20+
* @author 李玉江[QQ:1032694760]
21+
* @since 2017/06/24
22+
*/
23+
public class MultiplePicker extends ConfirmPopup<ScrollView> {
24+
private List<String> items = new ArrayList<>();
25+
private LinearLayout layout;
26+
private OnItemPickListener onItemPickListener;
27+
28+
public MultiplePicker(Activity activity, String[] items) {
29+
this(activity, Arrays.asList(items));
30+
}
31+
32+
public MultiplePicker(Activity activity, List<String> items) {
33+
super(activity);
34+
this.items = items;
35+
}
36+
37+
public void setOnItemPickListener(OnItemPickListener onItemPickListener) {
38+
this.onItemPickListener = onItemPickListener;
39+
}
40+
41+
@NonNull
42+
@Override
43+
protected ScrollView makeCenterView() {
44+
ScrollView scrollView = new ScrollView(activity);
45+
layout = new LinearLayout(activity);
46+
layout.setOrientation(LinearLayout.VERTICAL);
47+
for (String item : items) {
48+
LinearLayout line = new LinearLayout(activity);
49+
line.setOrientation(LinearLayout.HORIZONTAL);
50+
line.setGravity(Gravity.CENTER);
51+
TextView textView = new TextView(activity);
52+
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, WRAP_CONTENT, 1.0f);
53+
lp.gravity = Gravity.CENTER;
54+
textView.setLayoutParams(lp);
55+
textView.setText(item);
56+
textView.setGravity(Gravity.CENTER);
57+
line.addView(textView);
58+
CheckBox checkBox = new CheckBox(activity);
59+
checkBox.setLayoutParams(new LinearLayout.LayoutParams(0, WRAP_CONTENT, 0.4f));
60+
line.addView(checkBox);
61+
layout.addView(line);
62+
}
63+
scrollView.addView(layout);
64+
return scrollView;
65+
}
66+
67+
@Override
68+
protected void onSubmit() {
69+
if (onItemPickListener == null) {
70+
return;
71+
}
72+
List<String> checked = new ArrayList<>();
73+
for (int i = 0, count = layout.getChildCount(); i < count; i++) {
74+
LinearLayout line = (LinearLayout) layout.getChildAt(i);
75+
CheckBox checkBox = (CheckBox) line.getChildAt(1);
76+
if (checkBox.isChecked()) {
77+
TextView textView = (TextView) line.getChildAt(0);
78+
checked.add(textView.getText().toString());
79+
}
80+
}
81+
onItemPickListener.onItemPicked(checked.size(), checked);
82+
}
83+
84+
public interface OnItemPickListener {
85+
86+
void onItemPicked(int count, List<String> items);
87+
88+
}
89+
90+
}

0 commit comments

Comments
 (0)