File tree Expand file tree Collapse file tree
app/src/main/java/com/tick/conditiondialogdemo
conditiondialog/src/main/java/com/tick/conditiondialog Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ public class MainActivity extends AppCompatActivity implements VehicleConditionS
2525 private TextView mTextView ;
2626 private VehicleCdSelector mVehicleCdSelector ;
2727 private CarrierTypeCdSelector mTypeCdSelector ;
28+ private String mSelectedType ;
2829
2930 @ Override
3031 protected void onCreate (Bundle savedInstanceState ) {
@@ -41,7 +42,7 @@ protected void onCreate(Bundle savedInstanceState) {
4142 mVehicleButton = findViewById (R .id .btVehicel );
4243 mVehicleButton .setOnClickListener (v -> mVehicleCdSelector .show (v ));
4344 mCarrierTypeButton = findViewById (R .id .btCarrierType );
44- mCarrierTypeButton .setOnClickListener (v -> mTypeCdSelector .show (v ));
45+ mCarrierTypeButton .setOnClickListener (v -> mTypeCdSelector .show (v , mSelectedType ));
4546 }
4647
4748 public String getContent (VehicleCondition condition ) {
@@ -108,6 +109,7 @@ public void onSure(List<CarrierType> carrierTypes) {
108109 result .append ("," );
109110 }
110111 }
111- mTextView .setText (result .toString ());
112+ mSelectedType = result .toString ();
113+ mTextView .setText (mSelectedType );
112114 }
113115}
Original file line number Diff line number Diff line change 88import android .widget .CheckBox ;
99
1010import java .util .ArrayList ;
11+ import java .util .List ;
1112
1213/**
1314 * 条件选择框适配器
@@ -122,6 +123,42 @@ public final void onCheckItemClick(int position) {
122123 notifyDataSetChanged ();
123124 }
124125
126+ /**
127+ * 标记已经选中的条件
128+ *
129+ * @param args 选中条件数组
130+ */
131+ public final void setItemClicked (String [] args ) {
132+ if (args == null || args .length == 0 ) {
133+ return ;
134+ }
135+ if (TYPE_SINGLE == mType ) {
136+ //单选模式
137+ clearCheck ();
138+ String selected = args [0 ];
139+ for (T t : mConditions ) {
140+ if (selected .equals (t .getValue ())) {
141+ t .setCheck (true );
142+ mSelectChilds .add (t );
143+ break ;
144+ }
145+ }
146+ } else {
147+ //多选模式
148+ clearCheck ();
149+ for (String select : args ) {
150+ for (T t : mConditions ) {
151+ if (select .equals (t .getValue ())) {
152+ t .setCheck (true );
153+ mSelectChilds .add (t );
154+ }
155+ }
156+ }
157+ }
158+ notifyDataSetChanged ();
159+ }
160+
161+
125162 public ArrayList <T > getSelectChilds () {
126163 return mSelectChilds ;
127164 }
Original file line number Diff line number Diff line change 22
33import android .content .Context ;
44import android .support .v4 .content .ContextCompat ;
5+ import android .text .TextUtils ;
56import android .util .DisplayMetrics ;
67import android .view .Gravity ;
78import android .view .LayoutInflater ;
@@ -87,6 +88,14 @@ public void show(View v) {
8788 mTop .animate ().alpha (1f ).setDuration (100 ).setStartDelay (600 );
8889 }
8990
91+ public void show (View v , String types ) {
92+ if (!TextUtils .isEmpty (types )) {
93+ String [] conditions = types .split ("," );
94+ mTypeAdapter .setItemClicked (conditions );
95+ }
96+ show (v );
97+ }
98+
9099 public void hide () {
91100 mTop .setAlpha (0f );
92101 mTop .postDelayed (this ::dismiss , 10 );
You can’t perform that action at this time.
0 commit comments