我必须做一份人员名单。 此列表包含2个字段,名称和姓氏。
我创建了一个listview,其模板如下:
<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)
任何人都可以帮助我吗?
答案 0 :(得分:1)
我的问题是由项目对象数据引起的:
$.partenairesListSection.appendItems([{
template:'template',
field_name:'',
field_lastname:'',
}]);
&#34; field_name&#34; 和&#34; field_lastname&#34; 是我的文本字段的绑定ID。 所以,为了设置一个值,我需要给它一个带有&#34;值的对象&#34;属性:
{
template:'template',
field_name:{value:''},
field_lastname:{value:''},
}
答案 1 :(得分:0)
从defaultItemTemplate="template"
移除ListView
并在template="template"
中添加ListSection
。有时Android会将随机元素添加到ListView
,defaultItemTemplate
无法处理
另外,您可以创建默认模板:
<ItemTemplate name="defaultTemplate" height="0dp">
<View height="0dp">
</View>
</ItemTemplate>