【问题标题】:Insert cities list inside a string-array in string.xml在 string.xml 的字符串数组中插入城市列表
【发布时间】:2014-01-04 18:56:09
【问题描述】:

我正在使用 string.xml 中的字符串数组开发包含 2 个 AutoCompleteTextView 的应用程序。
现在我通过在 string.xml 中插入一个包含一些项目的字符串数组来成功使用此方法。

   <string-array name="cities_array">
        <item>...</item>
        <item>...</item>
        <item>...</item>
        <item>...</item>    
        <item>...</item>
   </string-array>

问题是我想添加一个包含 1000 个项目的列表,我想知道传递该列表并向每一行添加一个模式是否是最佳选择?

【问题讨论】:

  • 最好的 -> 数据库,创建准备好的数据库并加载到 android 应用程序。我知道,因为我正在加载 +1K 城市,当您有非常大的列表时,自动完成需要花费大量时间在那个大列表中搜索。使用 db 和 cursor 将为您提供最佳解决方案

标签: android xml string


【解决方案1】:

这就是发明计算机的目的。我建议你编写一个 Java 程序来完成这项工作。通过添加标签将单词列表转换为 XML。类似的东西

BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream("/path/to/file.txt")));

StringBuilder output=new StringBuilder();

String line;
while((line=br.readLine())!=null) {
  output.append("<item>"+line+"</item>");  
}

// Write output to a file...

虽然使用一些 XML 生成器来执行此操作会更好。

【讨论】:

  • 是的,我建议您编写一个简单的 Java 程序,将单词列表转换为 XML 文件。然后您可以将该 XML 文件包含在您的 android 项目中。
【解决方案2】:

我使用 Place autocomplete google 服务解决了这个问题,所以这正是我所需要的。 对于其他用途(不是城市、国家等),建议使用数据库,感谢 deadfish 的建议。

这是我找到的一些示例:thisthis(使用一些 php 代码)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-19
    相关资源
    最近更新 更多