{ "id": "159986", "key": "AC-3592", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "12217", "key": "AC", "name": "Appcelerator - INBOX", "projectCategory": { "id": "10000", "description": "", "name": "Customer Service" } }, "resolution": { "id": "2", "description": "The problem described is an issue which will never be fixed.", "name": "Won't Fix" }, "resolutiondate": "2016-05-05T18:59:30.000+0000", "created": "2016-05-03T21:41:45.000+0000", "labels": [ "android" ], "versions": [ { "id": "17037", "name": "Appcelerator Studio 4.4.2", "archived": false, "released": false } ], "issuelinks": [], "assignee": { "name": "shossain", "key": "shossain", "displayName": "Shak Hossain", "active": false, "timeZone": "America/Los_Angeles" }, "updated": "2016-05-05T18:59:30.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "14544", "name": "Alloy", "description": "Please enter tickets related to the Alloy here." }, { "id": "14548", "name": "Titanium SDK & CLI", "description": "Please enter tickets related to the MobileSDK here." } ], "description": "Consider the following code below:\r\n\r\n\r\n{code:java}\r\nfunction doClick(e) {\r\n win.open();\r\n}\r\n\r\nvar picker = null;\r\nvar backBtn = null;\r\nvar selectedIdx = 0;\r\n\r\n$.index.open();\r\n\r\nvar win = Titanium.UI.createWindow({\r\n exitOnClose : false,\r\n navBarHidden : true\r\n});\r\n\r\nwin.addEventListener(\"open\", function() {\r\n\r\n if(null != picker) {\r\n //picker.setSelectedRow(0, selectedIdx, false);\r\n return;\r\n }\r\n\r\n picker = Titanium.UI.createPicker({\r\n width : \"75%\",\r\n height : \"50dip\",\r\n selectionIndicator : true\r\n });\r\n\r\n picker.addEventListener(\"change\", function(id) {\r\n selectedIdx = id.rowIndex;\r\n });\r\n\r\n var arr = [];\r\n for(var i = 0; i < 10; i++) {\r\n arr.push(Titanium.UI.createPickerRow({\r\n title : i,\r\n color : \"black\"\r\n }));\r\n }\r\n\r\n selectedIdx = 0;\r\n\r\n picker.add(arr);\r\n\r\n backBtn = Titanium.UI.createButton({\r\n bottom : \"10dip\",\r\n title : \"Close\"\r\n });\r\n backBtn.addEventListener(\"click\", function() {\r\n win.close();\r\n });\r\n\r\n win.add(picker);\r\n win.add(backBtn);\r\n});\r\n{code}\r\n\r\nIf the above code is executed with SDK 5.2.0.GA or 5.2.2.GA, then you will see that the picker value is not being retained. After ever open/close of the window, even if we reuse the old picker object. But, if you uncomment the setSelectedRow (hack code I would say), then it behaves as required.\r\n\r\nAnyone faced such issue or is aware of a proper solution or root cause for it.", "attachment": [], "flagged": false, "summary": "Android Picker not retaining selected value", "creator": { "name": "soumyakantikar", "key": "soumyakantikar", "displayName": "Soumya Kanti Kar", "active": true, "timeZone": "America/Havana" }, "subtasks": [], "reporter": { "name": "soumyakantikar", "key": "soumyakantikar", "displayName": "Soumya Kanti Kar", "active": true, "timeZone": "America/Havana" }, "environment": "OS => OS X 10.11\r\nSDK => 5.2.2.GA\r\nPlatform => Android 4.4.2 (Galaxy S3)\r\nAlloy => 1.6", "comment": { "comments": [ { "id": "384665", "author": { "name": "nsalahin", "key": "nsalahin", "displayName": "Nazmus Salahin", "active": true, "timeZone": "Asia/Dhaka" }, "body": "Hello,\r\nI am able to reproduce this issue with given code and given step.\r\nBut to my understanding this is expected behavior. The picker is attached to a window and on Android starting with Release 3.2.0, all the windows are heavyweight. A heavyweight window is associated with a new Android Activity. So when the window is closed the activity is closed and so will be the picker. It that case the picker is not supposed retain its selected value.\r\n\r\nThanks\r\n\r\n*Environment*:\r\n\r\n*Device info:* Nexus7 (android 6.0.1)\r\n*Node.js Version:* 0.12.7\r\n*npm Version:* 2.11.3\r\n*Titanium SDKs:* 5.2.2.GA and 5.2.1.GA\r\n*Java Development Kit Version:* 1.8.0_73\r\n*Titanium CLI Version:* 5.0.5\r\n*Appcelerator CLI Version:* 5.2.2\r\n*Appcelerator Studio:* 4.5.0", "updateAuthor": { "name": "nsalahin", "key": "nsalahin", "displayName": "Nazmus Salahin", "active": true, "timeZone": "Asia/Dhaka" }, "created": "2016-05-04T05:45:39.000+0000", "updated": "2016-05-04T05:45:39.000+0000" }, { "id": "384730", "author": { "name": "soumyakantikar", "key": "soumyakantikar", "displayName": "Soumya Kanti Kar", "active": true, "timeZone": "America/Havana" }, "body": "But shouldn't the picker retain the last selected value? I am not creating a new object of the picker, I am just closing/opening the window. Also, if I un-comment the commented line, then it works, meaning that the internal state of the picker is being reset to the default value after closing and opening the window. We need to manually restore the last selected value to make it work properly.\r\n\r\nAlso if we add a textfield along with the picker, then the textfield retains its value, during the opening/closing of the window.", "updateAuthor": { "name": "soumyakantikar", "key": "soumyakantikar", "displayName": "Soumya Kanti Kar", "active": true, "timeZone": "America/Havana" }, "created": "2016-05-04T14:59:10.000+0000", "updated": "2016-05-04T15:25:04.000+0000" }, { "id": "384734", "author": { "name": "sdarda", "key": "sdarda", "displayName": "Sharif AbuDarda", "active": false, "timeZone": "Asia/Dhaka" }, "body": "Hello, \r\n\r\nYou have to set the setSelectedRow method after picker has been displayed for automatically select a row in each column. For reference see the example codes http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.Picker-method-setSelectedRow. \r\n\r\nSo, according to your code, the commented code must be at the end after you add picker to window in your window open function.\r\n\r\nRegards,\r\nSharif.", "updateAuthor": { "name": "sdarda", "key": "sdarda", "displayName": "Sharif AbuDarda", "active": false, "timeZone": "Asia/Dhaka" }, "created": "2016-05-04T15:30:54.000+0000", "updated": "2016-05-04T15:30:54.000+0000" }, { "id": "384735", "author": { "name": "soumyakantikar", "key": "soumyakantikar", "displayName": "Soumya Kanti Kar", "active": true, "timeZone": "America/Havana" }, "body": "If I move the commented code at the end, after adding the picker to the window, then it will work for the first time. After I close the window and open it again, the last selected value is not being retained. For example, if I set the selectedIdx as 5, then it will work properly. Now I change it to 8 and close the window. On opening the window again, it will show 5, instead of 8, the last selected value of 8.", "updateAuthor": { "name": "soumyakantikar", "key": "soumyakantikar", "displayName": "Soumya Kanti Kar", "active": true, "timeZone": "America/Havana" }, "created": "2016-05-04T15:34:06.000+0000", "updated": "2016-05-04T15:34:06.000+0000" }, { "id": "384891", "author": { "name": "sdarda", "key": "sdarda", "displayName": "Sharif AbuDarda", "active": false, "timeZone": "Asia/Dhaka" }, "body": "Hello, \r\n\r\nRemove the \"selectedIdx = 0;\" in the open function, and use the \"picker.setSelectedRow(0, selectedIdx, false);\". A heavyweight window is associated with a new Android Activity. So when the window is closed the activity is closed and so will be the picker. It that case the picker is not supposed retain its selected value. This should be the default behavior. If you want to retain the picker selected value you have to use the commented line of code. Closing this issue.\r\n\r\nRegards,\r\nSharif.", "updateAuthor": { "name": "sdarda", "key": "sdarda", "displayName": "Sharif AbuDarda", "active": false, "timeZone": "Asia/Dhaka" }, "created": "2016-05-05T18:59:08.000+0000", "updated": "2016-05-05T18:59:08.000+0000" } ], "maxResults": 5, "total": 5, "startAt": 0 } } }