【问题标题】:Appcelerator - ListView error (only in Android)Appcelerator - ListView 错误(仅在 Android 中)
【发布时间】:2016-08-02 15:47:46
【问题描述】:

我正在使用 Appcelerator 框架开发一个应用程序(使用 Appcelerator Studio),但我遇到了一个没有解决方案的问题(还)。

我正在创建一个包含世界上所有国家/地区及其相关电话前缀的列表,即“United States +1”、“United Kingdom +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;
});

您知道为什么我只能在 Android 设备中看到我的 ListItems 中的 countryNamecountryPrefix 吗?

【问题讨论】:

    标签: android listview appcelerator-titanium appcelerator-studio


    【解决方案1】:

    我发现问题出在哪里。我认为是 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"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多