Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-26155

Android: ListView setItems causes error after updateItemAt used with custom template

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: Release 7.2.0
    • Fix Version/s: Release 7.5.0
    • Component/s: Android
    • Labels:
    • Environment:

      Description

      I am attempting to use ListView to hold a series of Switch + Labels for a question and answer app. When the user selects one answer (either by clicking the switch or clicking the label), I am setting all other Switches to false so that only one answer can be selected.

      Below is the minimum code to reproduce the issue. What you will see is if the user does not click any Switches / Labels and just clicks the button, the first set of answers is replaced by the second set of answers without any issue. If the user clicks a Switch / Label, which causes updateItemAt() to be used on each row, then when the button is pressed to replace the answers shown, an error occurs.


      <Alloy>
      <Window id="questWin" title="Questions and Answers">
      	<View layout="horizontal">
      	  <ListView top="0" left="24dp" width="Ti.UI.FILL" height="Ti.UI.SIZE" id="answerList" defaultItemTemplate="answerTmpl" separatorColor="#BBB" onItemclick="clickAns">
      	    <Templates>
      	      <ItemTemplate top="8dp" bottom="8dp" width="Ti.UI.FILL" height="Ti.UI.SIZE" name="answerTmpl">
      	        <View top="0" left="0" layout="horizontal" width="Ti.UI.FILL" height="Ti.UI.SIZE">
      	          <Switch left="0" width="Ti.UI.SIZE" height="Ti.UI.SIZE" style="Titanium.UI.Android.SWITCH_STYLE_CHECKBOX" bindId="ansCheck" />
      	          <Label left="8dp" width="Ti.UI.FILL" height="Ti.UI.SIZE" bindId="ansLabel" />
      	        </View>
      	      </ItemTemplate>
      	    </Templates>
      	    <ListSection id="answerSec" />
      	  </ListView>
      	  <Button top="12dp" width="160dp" onClick="clickSubmitBtn">Submit</Button>
      	</View>  
      </Window>
      </Alloy>
      


      // Arguments passed into this controller can be accessed via the `$.args` object directly or:
      var args = $.args;
      var giSelAns = null;
       
      function clickAns(e) {
      	giSelAns = e.itemIndex;
       
      	for (var iCnt = 0; iCnt < $.answerSec.items.length; iCnt++) {
      		var item = $.answerSec.getItemAt(iCnt);
      		if (iCnt == giSelAns)
      			item.ansCheck.value = true;
      		else
      			item.ansCheck.value = false;
      		$.answerSec.updateItemAt(iCnt, item);
      	}
      }
       
      function clickSubmitBtn() {
      	// Skipping code to check correct, answer, etc.
      	answers = [
      		{ ansLabel: { text: "Second Answer 1" }, ansCheck: { isCorrect: false } },
      		{ ansLabel: { text: "Second Answer 2" }, ansCheck: { isCorrect: true } },
      		{ ansLabel: { text: "Second Answer 3" }, ansCheck: { isCorrect: false } },
      	];
      	$.answerSec.setItems(answers);	
      }
       
      $.questWin.addEventListener("open", function() {
      	answers = [
      		{ ansLabel: { text: "First Answer 1" }, ansCheck: { isCorrect: true } },
      		{ ansLabel: { text: "First Answer 2" }, ansCheck: { isCorrect: false } },
      		{ ansLabel: { text: "First Answer 3" }, ansCheck: { isCorrect: false } },
      	];
      	$.answerSec.setItems(answers);
      });
       
      $.questWin.addEventListener("close", function(){
        $.destroy();
      });
       
      $.questWin.open();
      


      [INFO] :   ViewRootImpl: finishMotionEvent: handled = true stage=10: View Post IME stage,inputElapseTime=1 eventTime = 23749878 downTime = 23749878 title= edu.bju.logia/org.appcelerator.titanium.TiActivity
      [ERROR] :  TiApplication: (main) [11565,11565] Sending event: exception on thread: main msg:java.lang.IllegalArgumentException: Unable to convert null to boolean.; Titanium 7.2.0,2018/06/07 05:21,undefined
      [ERROR] :  TiApplication: java.lang.IllegalArgumentException: Unable to convert null to boolean.
      [ERROR] :  TiApplication:     at org.appcelerator.titanium.util.TiConvert.toBoolean(TiConvert.java:360)
      [ERROR] :  TiApplication:     at org.appcelerator.titanium.util.TiConvert.toBoolean(TiConvert.java:390)
      [ERROR] :  TiApplication:     at ti.modules.titanium.ui.widget.TiUISwitch.processProperties(TiUISwitch.java:53)
      [ERROR] :  TiApplication:     at ti.modules.titanium.ui.widget.listview.ListSectionProxy.populateViews(ListSectionProxy.java:891)
      [ERROR] :  TiApplication:     at ti.modules.titanium.ui.widget.listview.TiListView$TiBaseAdapter.getView(TiListView.java:276)
      [ERROR] :  TiApplication:     at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220)
      [ERROR] :  TiApplication:     at android.widget.AbsListView.obtainView(AbsListView.java:2405)
      [ERROR] :  TiApplication:     at android.widget.ListView.makeAndAddView(ListView.java:1909)
      [ERROR] :  TiApplication:     at android.widget.ListView.fillDown(ListView.java:723)
      [ERROR] :  TiApplication:     at android.widget.ListView.fillSpecific(ListView.java:1388)
      [ERROR] :  TiApplication:     at android.widget.ListView.layoutChildren(ListView.java:1690)
      [ERROR] :  TiApplication:     at android.widget.AbsListView.onLayout(AbsListView.java:2201)
      [ERROR] :  TiApplication:     at android.view.View.layout(View.java:16833)
      [ERROR] :  TiApplication:     at android.view.ViewGroup.layout(ViewGroup.java:5438)
      [ERROR] :  TiApplication:     at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:610)
      [ERROR] :  TiApplication:     at ti.modules.titanium.ui.widget.listview.TiListView$ListViewWrapper.onLayout(TiListView.java:157)
      [ERROR] :  TiApplication:     at android.view.View.layout(View.java:16833)
      [ERROR] :  TiApplication:     at android.view.ViewGroup.layout(ViewGroup.java:5438)
      [ERROR] :  TiApplication:     at org.appcelerator.titanium.view.TiCompositeLayout.onLayout(TiCompositeLayout.java:853)
      [ERROR] :  TiApplication:     at android.view.View.layout(View.java:16833)
      [ERROR] :  TiApplication:     at android.view.ViewGroup.layout(ViewGroup.java:5438)
      [ERROR] :  TiApplication:     at org.appcelerator.titanium.view.TiCompositeLayout.onLayout(TiCompositeLayout.java:853)
      [ERROR] :  TiApplication:     at android.view.View.layout(View.java:16833)
      [ERROR] :  TiApplication:     at android.view.ViewGroup.layout(ViewGroup.java:5438)
      [ERROR] :  TiApplication:     at org.appcelerator.titanium.view.TiCompositeLayout.onLayout(TiCompositeLayout.java:853)
      [ERROR] :  TiApplication:     at android.view.View.layout(View.java:16833)
      [ERROR] :  TiApplication:     at android.view.ViewGroup.layout(ViewGroup.java:5438)
      [ERROR] :  TiApplication:     at org.appcelerator.titanium.view.TiCompositeLayout.onLayout(TiCompositeLayout.java:853)
      [ERROR] :  TiApplication:     at android.view.View.layout(View.java:16833)
      [ERROR] :  TiApplication:     at android.view.ViewGroup.layout(ViewGroup.java:5438)
      [ERROR] :  TiApplication:     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
      [ERROR] :  TiApplication:     at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
      [ERROR] :  TiApplication:     at android.view.View.layout(View.java:16833)
      [ERROR] :  TiApplication:     at android.view.ViewGroup.layout(ViewGroup.java:5438)
      [ERROR] :  TiApplication:     at android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:443)
      [ERROR] :  TiApplication:     at android.view.View.layout(View.java:16833)
      [ERROR] :  TiApplication:     at android.view.ViewGroup.layout(ViewGroup.java:5438)
      [ERROR] :  TiApplication:     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
      [ERROR] :  TiApplication:     at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
      [ERROR] :  TiApplication:     at android.view.View.layout(View.java:16833)
      [ERROR] :  TiApplication:     at android.view.ViewGroup.layout(ViewGroup.java:5438)
      [ERROR] :  TiApplication:     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
      [ERROR] :  TiApplication:     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
      [ERROR] :  TiApplication:     at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
      [ERROR] :  TiApplication:     at android.view.View.layout(View.java:16833)
      [ERROR] :  TiApplication:     at android.view.ViewGroup.layout(ViewGroup.java:5438)
      [ERROR] :  TiApplication:     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
      [ERROR] :  TiApplication:     at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
      [ERROR] :  TiApplication:     at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:2720)
      [ERROR] :  TiApplication:     at android.view.View.layout(View.java:16833)
      [ERROR] :  TiApplication:     at android.view.ViewGroup.layout(ViewGroup.java:5438)
      [ERROR] :  TiApplication:     at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2474)
      [ERROR] :  TiApplication:     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2131)
      [ERROR] :  TiApplication:     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1233)
      [ERROR] :  TiApplication:     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6560)
      [ERROR] :  TiApplication:     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:919)
      [ERROR] :  TiApplication:     at android.view.Choreographer.doCallbacks(Choreographer.java:710)
      [ERROR] :  TiApplication:     at android.view.Choreographer.doFrame(Choreographer.java:645)
      [ERROR] :  TiApplication:     at a
      [INFO] :   Process: Sending signal. PID: 25349 SIG: 9
      [LiveView] Client disconnected
      [LiveView] Client connected
      

        Attachments

          Activity

            People

            • Assignee:
              gmathews Gary Mathews
              Reporter:
              rkenny Russell Kenny
              Reviewer:
              Yordan Banev
              Tester:
              Samir Mohammed
            • Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Titanium SDK/CLI <> Titanium Mobile
                  Synced with:
                  TIMOB-6417
                  Sync status:
                  ERROR
                  Last received:
                  Last sent:

                  Git Source Code