Repository: incubator-weex
Updated Branches:
  refs/heads/master f77db8fe5 -> a7b912361


*[android] fix selection error in picker


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/a7b91236
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/a7b91236
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/a7b91236

Branch: refs/heads/master
Commit: a7b912361f1f31b7baabc4512b450b296ba3b0bc
Parents: 4d06e61
Author: misakuo <[email protected]>
Authored: Tue Mar 13 18:11:49 2018 +0800
Committer: misakuo <[email protected]>
Committed: Thu Mar 15 14:11:06 2018 +0800

----------------------------------------------------------------------
 .../weex/appfram/pickers/WXPickersModule.java   | 68 +++++++++-----------
 1 file changed, 29 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/a7b91236/android/sdk/src/main/java/com/taobao/weex/appfram/pickers/WXPickersModule.java
----------------------------------------------------------------------
diff --git 
a/android/sdk/src/main/java/com/taobao/weex/appfram/pickers/WXPickersModule.java
 
b/android/sdk/src/main/java/com/taobao/weex/appfram/pickers/WXPickersModule.java
index 426412f..ef46f8f 100644
--- 
a/android/sdk/src/main/java/com/taobao/weex/appfram/pickers/WXPickersModule.java
+++ 
b/android/sdk/src/main/java/com/taobao/weex/appfram/pickers/WXPickersModule.java
@@ -32,7 +32,6 @@ import android.widget.AdapterView;
 import android.widget.ArrayAdapter;
 import android.widget.Button;
 import android.widget.Checkable;
-import android.widget.CheckedTextView;
 import android.widget.ListView;
 import android.widget.TextView;
 
@@ -185,29 +184,36 @@ public class WXPickersModule extends WXModule {
     private void performSinglePick(final List<String> items, final Map<String, 
Object> options, final JSCallback callback) {
         selected = getOption(options, KEY_INDEX, 0);
         final int textColor = getColor(options, KEY_TEXT_COLOR, 
Color.TRANSPARENT);
+        final int selectionColor = getColor(options, KEY_SELECTION_COLOR, 
Color.TRANSPARENT);
+        final ArrayAdapter adapter = new ArrayAdapter<String>(
+            mWXSDKInstance.getContext(),
+            android.R.layout.simple_list_item_single_choice,
+            items) {
+            @NonNull
+            @Override
+            public View getView(int position, View convertView, @Nullable 
ViewGroup parent) {
+                View itemView =  super.getView(position, convertView, parent);
+
+                if (itemView != null && itemView instanceof Checkable) {
+                    boolean needSelected = position == selected;
+                    ((Checkable) itemView).setChecked(needSelected);
+
+                    if (needSelected) {
+                        itemView.setBackgroundColor(selectionColor);
+                    } else {
+                        itemView.setBackgroundColor(Color.TRANSPARENT);
+                    }
+                }
+
+                if (itemView instanceof TextView && textColor != 
Color.TRANSPARENT) {
+                    ((TextView) itemView).setTextColor(textColor);
+                }
 
+                return itemView;
+            }
+        };
         final AlertDialog dialog =  new 
AlertDialog.Builder(mWXSDKInstance.getContext())
-                .setAdapter(
-                        new ArrayAdapter<String>(
-                                mWXSDKInstance.getContext(),
-                                
android.R.layout.simple_list_item_single_choice,
-                                items) {
-                            @NonNull
-                            @Override
-                            public View getView(int position, View 
convertView, @Nullable ViewGroup parent) {
-                                View itemView =  super.getView(position, 
convertView, parent);
-
-                                if (itemView != null && itemView instanceof 
CheckedTextView) {
-                                    ((CheckedTextView) 
itemView).setChecked(position == selected);
-                                }
-
-                                if (itemView instanceof TextView && textColor 
!= Color.TRANSPARENT) {
-                                    ((TextView) 
itemView).setTextColor(textColor);
-                                }
-
-                                return itemView;
-                            }
-                        } , null)
+                .setAdapter(adapter, null)
                 .setPositiveButton(android.R.string.ok, new 
DialogInterface.OnClickListener() {
                     @Override
                     public void onClick(DialogInterface dialog, int which) {
@@ -239,26 +245,10 @@ public class WXPickersModule extends WXModule {
 
         final ListView listView = dialog.getListView();
         listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
-            private View previousView;
-            private int selectionColor = getColor(options, 
KEY_SELECTION_COLOR, Color.TRANSPARENT);
-
             @Override
             public void onItemClick(AdapterView<?> parent, View view, int 
position, long id) {
                 selected = position;
-                if (previousView == view) {
-                    return;
-                }
-                if (previousView != null) {
-                    previousView.setBackgroundColor(Color.TRANSPARENT);
-                    if (previousView instanceof Checkable) {
-                        ((Checkable) previousView).toggle();
-                    }
-                }
-                if (view instanceof Checkable) {
-                    ((Checkable) view).toggle();
-                }
-                view.setBackgroundColor(selectionColor);
-                previousView = view;
+                adapter.notifyDataSetChanged();
             }
         });
 

Reply via email to