0

我正在開發一個Appcelerator框架的應用程序(使用Appcelerator Studio),但我遇到了沒有解決方案(還)的問題。Appcelerator - ListView錯誤(僅適用於Android)

我創造與世界所有國家和其相關的電話前綴列表,即「美國+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中的countryNamecountryPrefix

回答

0

我想通了問題在哪裏。我認爲是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"/> 
相關問題