[英]Appcelerator - ListView error (only in Android)
我正在使用Appcelerator框架(使用Appcelerator Studio)開發應用程序,但是遇到了沒有解決方案的問題(尚未解決)。
我正在創建一個列表,其中包含世界上所有國家及其相關的電話前綴,即“ 美國+1 ”,“ 英國+44 ”等等。 我正在使用ListView ,因為用戶必須選擇一個。 在iOS上,一切正常,但是當我在Android物理設備中運行該應用程序時, ListItems全部顯示,但不是文本。 我的意思是,在iOS中,我在每一行中看到所有國家/地區及其對應的名稱。 在Android中,我看到ListView中有150多行,我可以單擊這些行,應用程序將選擇相應的國家/地區,但行中看不到打印的文本 。
我正在使用ItemTemplate ,然后創建(使用Javascript) ListSection,向其中添加元素(使用bindId屬性動態添加元素)。
我已經看到其他使用Appcelerator構建的應用程序沒有此問題,因此我試圖找出錯誤的地方。
countryList.xml
<Alloy>
<Window class="container" id="win_firstStart_countryList">
<ListView id="ListView_prefixes">
<SearchBar id="searchBar_countries"/>
<Templates>
<ItemTemplate id="countryCodeTempl" name="countryCodeTempl">
<Label id="label_countryName"/>
<Label id="label_countryPrefix"/>
</ItemTemplate>
</Templates>
</ListView>
</Window>
</Alloy>
countryList.tss
"#ListView_prefixes": {
"left": "0.00%",
"top": "0%",
"defaultItemTemplate": "countryCodeTempl"
},
"#countryCodeTempl": {
"color": "#000000",
"backgroundColor": "#000000",
},
"#label_countryName": {
"color": "#000000",
"font": {fontSize:'18dp',fontFamily:'',fontStyle:'',fontWeight:''},
"left": "3%",
"top": "4dp",
"bindId": "countryName",
"height": Ti.UI.SIZE,
"width": "45%",
"backgroundColor": "#ff0000",
},
"#label_countryPrefix": {
"bindId": "countryPrefix",
"top": "4dp",
"width": "45%",
"height": Ti.UI.SIZE,
"color": "#000000",
"font": {fontSize:'18dp',fontFamily:'',fontStyle:'',fontWeight:''},
"right": "3%",
"textAlign": "right"
},
"#win_firstStart_countryList": {
"left": "0.00%",
"top": "0%",
"height": "100%",
"width": "100.00%",
"backgroundColor": "#ffffff",
}
countryList.js
var countrySection = Ti.UI.createListSection({});
var items = [];
var db = Ti.Database.open(DB_NAME);
var query = db.execute("SELECT country_code, country_name, country_prefix from countries");
while (query.isValidRow()) {
items.push({
countryName: { text: query.fieldByName('country_name') },
countryPrefix: { text: "+ " + query.fieldByName('country_prefix') },
properties: {
title: query.fieldByName('country_name'),
itemId: query.fieldByName('country_code'),
searchableText: query.fieldByName('country_name'),
caseInsensitiveSearch: true
}
});
query.next();
}
query.close();
db.close();
countrySection.setItems(items);
$.ListView_prefixes.sections = [countrySection];
$.ListView_prefixes.searchView = $.searchBar_countries;
$.searchBar_countries.addEventListener('change', function(e){
$.ListView_prefixes.searchText = e.value;
});
您是否有一個想法,為什么我只能在Anddroid設備中看不到ListItems中的countryName
和countryPrefix
?
我找出了問題所在。 我認為這是Appcelerator Studio的錯誤。 設置“ bindId”屬性時,無法在.tss文件中進行設置,但必須直接在ItemTemplate元素內進行設置。 就我而言
<Label id="label_countryName"/>
<Label id="label_countryPrefix"/>
相反,為了使其工作, 我應該編寫以下代碼 :
<Label bindId="countryName" id="label_countryName"/>
<Label bindId="countryPrefix" id="label_countryPrefix"/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.