简体   繁体   English

Appcelerator-ListView错误(仅在Android中)

[英]Appcelerator - ListView error (only in Android)

I am developing an app with Appcelerator framework (using Appcelerator Studio), but I have encountered aproblem without a solution (yet). 我正在使用Appcelerator框架(使用Appcelerator Studio)开发应用程序,但是遇到了没有解决方案的问题(尚未解决)。

I am creating a list with all the countries in the world and their related phone prefix, ie " United States +1 ", " United Kingdom +44 " and so on. 我正在创建一个列表,其中包含世界上所有国家及其相关的电话前缀,即“ 美国+1 ”,“ 英国+44 ”等等。 I am using a ListView , since the user will have to choose one. 我正在使用ListView ,因为用户必须选择一个。 On iOS everything works great, but when I run the app inside my Android phisical device, the ListItems are all presents, but not their text. 在iOS上,一切正常,但是当我在Android物理设备中运行该应用程序时, ListItems全部显示,但不是文本。 What I mean is that, in iOS I see all the countries and their ccorresponding name in each line. 我的意思是,在iOS中,我在每一行中看到所有国家/地区及其对应的名称。 In Android I see that there are 150+ lines inside my ListView, I can click on those lines, the application will choose the corresponding country, but I don't see the printed text in the rows . 在Android中,我看到ListView中有150多行,我可以单击这些行,应用程序将选择相应的国家/地区,但行中看不到打印的文本

I am using an ItemTemplate , and then I create (with Javascript) a ListSection to which I add the elements (adding them dynamically using the bindId property). 我正在使用ItemTemplate ,然后创建(使用Javascript) ListSection,向其中添加元素(使用bindId属性动态添加元素)。

I've seen that other applications built with Appcelerator don't have this problem, so I am trying to figure out where I am wrong. 我已经看到其他使用Appcelerator构建的应用程序没有此问题,因此我试图找出错误的地方。

countryList.xml 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 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 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;
});

Do you have an idea about why I cannot see the countryName and countryPrefix inside my ListItems only in Anddroid devices? 您是否有一个想法,为什么我只能在Anddroid设备中看不到ListItems中的countryNamecountryPrefix

I figured out where is the problem. 我找出了问题所在。 I think is a bug of Appcelerator Studio. 我认为这是Appcelerator Studio的错误。 When you set the "bindId" property, you cannot set in the .tss file, but you have to set directly inside the ItemTemplate element. 设置“ bindId”属性时,无法在.tss文件中进行设置,但必须直接在ItemTemplate元素内进行设置。 In my case I did 就我而言

<Label id="label_countryName"/>
<Label id="label_countryPrefix"/>

Instead, in order to let it work, I should have write the following code : 相反,为了使其工作, 我应该编写以下代码

<Label bindId="countryName" id="label_countryName"/>
<Label bindId="countryPrefix" id="label_countryPrefix"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM