Titanium JIRA Archive
Appcelerator Community (AC)

[AC-5735] Android: TextField in ListView loses value on scroll (question)

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionDone
Resolution Date2018-05-14T15:19:54.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
LabelsListView, TextField, scroll
ReporterChristoph Eck
AssigneeShak Hossain
Created2018-05-14T09:16:34.000+0000
Updated2018-05-14T15:20:00.000+0000

Description

*Issue* Lost value on scrolling down the ListView. *actual behavior* 1. Compile and start on device 2. Enter a text like "Hello 123" 3. Scroll down and up again 4. You read "Hello" *expected behavior* 1. Compile and start on device 2. Enter a text like "Hello 123" 3. Scroll down and up again 4. You read "Hello 123"

Attachments

FileDateSize
app.js2018-05-14T09:15:25.000+00002082

Comments

  1. Hans Knöchel 2018-05-14

    When working with text-fields or text-areas in list-views, you need to persist the value in the list via updateItemAt, so the internal data structure gets updated as well. This is a common scenario when working with list-views and is happening both natively and in Titanium.
  2. Rene Pot 2018-05-14

    Agreed with above. To add to this, the reason it is happening is because items that re-enter the visible area are re-rendered. This is also why a ListView can have thousands of rows and not crash a low-end device.
  3. Christoph Eck 2018-05-14

    Thanks for the feedback. I tried it out and I found a solution. Store text value on change event and update the textfield on scrollstart. *Store text value*
       events: {
           'change': function(evt) {						
               Ti.API.debug('change');
               textFieldValue = evt.value;
           },
       
    *Update the textfield on scrollstart*
       list.addEventListener('scrollstart', function(e) {
           Ti.API.info('scrollstart');
           section.updateItemAt(1, {
               template: 'myNotes', 
               myNotes: {
                   value: textFieldValue,
               }
           });
       });
       

JSON Source