【问题标题】:Titanium ListView with TextField do an error in Android带有TextField的Titanium ListView在Android中出错
【发布时间】:2015-02-03 13:44:47
【问题描述】:

我必须列出人员名单。 此列表有 2 个字段,名称和姓氏。

我创建了一个列表视图,模板如下:

                    <ListView id="partenairesList" defaultItemTemplate="template">
                        <Templates>
                            <ItemTemplate name="template">
                                <View class="textField-demi">
                                    <Label class="placeholder">Prénom</Label>
                                    <TextField bindId="field_name"></TextField>
                                    <View class="border-bottom textField-border"></View>
                                </View>
                                <View class="textField-demi textField-right">
                                    <Label class="placeholder">Nom</Label>
                                    <TextField bindId="field_lastname"></TextField>
                                    <View class="border-bottom textField-border"></View>
                                </View>
                            </ItemTemplate>
                        </Templates>
                        <ListSection id="partenairesListSection">
                        </ListSection>
                    </ListView>

这项工作在 ios 上。 但是当我在 android 的列表中添加项目时,应用程序会因错误而被终止。

这是我添加项目的功能:

function addEmptyItemPartenaire(){
    $.partenairesListSection.appendItems([{
        template:'template',
        field_name:'',
        field_lastname:'',
    }]);
}

这是有错误的控制台调试:

[WARN] :   TiUIScrollView: (main) [137999,176598] Scroll direction could not be determined based on the provided view properties. Default VERTICAL scroll direction being used. Use the 'scrollType' property to explicitly set the scrolling direction.
[INFO] :   I/dalvikvm-heap: Grow heap (frag case) to 15.674MB for 635812-byte allocation
[WARN] :   dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x40aa9300)
[ERROR] :  TiApplication: (main) [28953,205551] Sending event: exception on thread: main msg:java.lang.ClassCastException: java.lang.String cannot be cast to java.util.HashMap; Titanium 3.2.0,2013/12/20 10:57,d9182d6
[ERROR] :  TiApplication: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.HashMap
[ERROR] :  TiApplication:   at ti.modules.titanium.ui.widget.listview.TiListViewTemplate.updateOrMergeWithDefaultProperties(TiListViewTemplate.java:231)
[ERROR] :  TiApplication:   at ti.modules.titanium.ui.widget.listview.ListSectionProxy.processData(ListSectionProxy.java:432)
[ERROR] :  TiApplication:   at ti.modules.titanium.ui.widget.listview.ListSectionProxy.handleAppendItems(ListSectionProxy.java:492)
[ERROR] :  TiApplication:   at ti.modules.titanium.ui.widget.listview.ListSectionProxy.handleMessage(ListSectionProxy.java:236)
[ERROR] :  TiApplication:   at android.os.Handler.dispatchMessage(Handler.java:95)
[ERROR] :  TiApplication:   at android.os.Looper.loop(Looper.java:137)
[ERROR] :  TiApplication:   at android.app.ActivityThread.main(ActivityThread.java:4931)

有人可以帮助我吗?

【问题讨论】:

  • 这不是标准的 android sdk。抱歉,我无能为力。您应该在标题中包含钛
  • 我在标题中添加了 Titanium,谢谢。
  • 您在哪里定义“模板”?坐姿是什么样的?
  • 我的“模板”在合金 xml 视图中定义。谢谢你的回复,我发现了我的错误。

标签: android forms listview titanium titanium-alloy


【解决方案1】:

我的问题是由项目对象数据引起的:

$.partenairesListSection.appendItems([{
    template:'template',
    field_name:'',
    field_lastname:'',
}]);

"field_name""field_lastname" 是我的文本字段的绑定 ID。 所以,为了设置一个值,我需要给它一个具有“值”属性的对象:

{
    template:'template',
    field_name:{value:''},
    field_lastname:{value:''},
}

【讨论】:

    【解决方案2】:

    ListView 中删除defaultItemTemplate="template" 并在ListSection 中添加template="template"。有时Android向ListView添加随机元素,defaultItemTemplate无法处理

    另外你可以创建默认模板:

          <ItemTemplate name="defaultTemplate" height="0dp">
            <View height="0dp">
            </View>
          </ItemTemplate>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-19
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      • 1970-01-01
      • 2012-06-21
      • 1970-01-01
      相关资源
      最近更新 更多