@@ -147,33 +147,12 @@ public void onClick(View v) {
147
147
148
148
rootLayout .addView (buttonLayout );
149
149
150
- listView .setOnItemClickListener (new AdapterView .OnItemClickListener () {
151
- @ Override
152
- public void onItemClick (AdapterView <?> parent , View view , int position , long id ) {
153
- File item = fileList .get (position );
154
- if (EMPTY_PLACEHOLDER .equals (item .getName ())) return ;
155
-
156
- if (".." .equals (item .getName ())) {
157
- currentDir = currentDir .getParentFile ();
158
- FileDialogSelectUtils .this .refreshFileList ();
159
- } else if (item .isDirectory ()) {
160
- currentDir = item ;
161
- FileDialogSelectUtils .this .refreshFileList ();
162
- } else {
163
- if (singleSelect ) {
164
- selectedFiles .clear ();
165
- selectedFiles .add (item );
166
- } else {
167
- if (selectedFiles .contains (item )) {
168
- selectedFiles .remove (item );
169
- } else {
170
- selectedFiles .add (item );
171
- }
172
- }
173
- adapter .notifyDataSetChanged ();
174
- }
175
- }
176
- });
150
+ // listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
151
+ // @Override
152
+ // public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
153
+ // notifyViewChange(position);
154
+ // }
155
+ // });
177
156
178
157
AlertDialog .Builder builder = new AlertDialog .Builder (context , R .style .CustomDialogStyle );
179
158
builder .setView (rootLayout );
@@ -183,6 +162,31 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
183
162
refreshFileList ();
184
163
}
185
164
165
+ private void notifyViewChange (final int position ) {
166
+ File item = fileList .get (position );
167
+ if (EMPTY_PLACEHOLDER .equals (item .getName ())) return ;
168
+
169
+ if (".." .equals (item .getName ())) {
170
+ currentDir = currentDir .getParentFile ();
171
+ FileDialogSelectUtils .this .refreshFileList ();
172
+ } else if (item .isDirectory ()) {
173
+ currentDir = item ;
174
+ FileDialogSelectUtils .this .refreshFileList ();
175
+ } else {
176
+ if (singleSelect ) {
177
+ selectedFiles .clear ();
178
+ selectedFiles .add (item );
179
+ } else {
180
+ if (selectedFiles .contains (item )) {
181
+ selectedFiles .remove (item );
182
+ } else {
183
+ selectedFiles .add (item );
184
+ }
185
+ }
186
+ adapter .notifyDataSetChanged ();
187
+ }
188
+ }
189
+
186
190
private void refreshFileList () {
187
191
fileList .clear ();
188
192
@@ -303,7 +307,7 @@ public long getItemId(int position) {
303
307
}
304
308
305
309
@ Override
306
- public View getView (int position , View convertView , ViewGroup parent ) {
310
+ public View getView (final int position , View convertView , ViewGroup parent ) {
307
311
File file = fileList .get (position );
308
312
LinearLayout layout = new LinearLayout (context );
309
313
layout .setOrientation (LinearLayout .HORIZONTAL );
@@ -317,6 +321,12 @@ public View getView(int position, View convertView, ViewGroup parent) {
317
321
nameView .setTextSize (TypedValue .COMPLEX_UNIT_SP , itemTvSize );
318
322
nameView .setLayoutParams (new LinearLayout .LayoutParams (
319
323
0 , ViewGroup .LayoutParams .WRAP_CONTENT , 1 ));
324
+ layout .setOnClickListener (new View .OnClickListener () {
325
+ @ Override
326
+ public void onClick (View v ) {
327
+ notifyViewChange (position );
328
+ }
329
+ });
320
330
321
331
if (EMPTY_PLACEHOLDER .equals (file .getName ())) {
322
332
nameView .setText (R .string .not_found_file_child_content );
@@ -330,7 +340,12 @@ public View getView(int position, View convertView, ViewGroup parent) {
330
340
if (!file .isDirectory () && !file .getName ().equals (".." )) {
331
341
CheckBox checkBox = new CheckBox (context );
332
342
checkBox .setChecked (selectedFiles .contains (file ));
333
- checkBox .setEnabled (false );
343
+ checkBox .setOnClickListener (new View .OnClickListener () {
344
+ @ Override
345
+ public void onClick (View v ) {
346
+ notifyViewChange (position );
347
+ }
348
+ });
334
349
checkBox .setButtonDrawable (R .drawable .custom_checkbox );
335
350
336
351
// 设置右边距(比如 20dp)
0 commit comments