如何以编程方式将项目添加到arrayList中的stringArray? [英] How to add items to a stringArray in an arrayList programmatically?

查看:117
本文介绍了如何以编程方式将项目添加到arrayList中的stringArray?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的 res / values 文件夹中的 array.xml 文件:

This is my array.xml file in the res/values folder:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="updateInterval">
           <item name="1000">Pico TTS</item>
          <item name="5000">Invox TTs</item>
    </string-array>
</resources>

我需要在 updateInterval 数组列表。如何才能以编程方式添加动态来自服务器的项目?

I need to add some more items to the updateInterval array list. How can I add the items that are dynamically coming from server programmatically?

推荐答案

您不能直接将项目添加到该字符串数组中。

You can't add item directly to that string array.

但是您可以使用该数组并向该字符串数组中动态添加元素。

But you can use that array and dynamically add elements to that string array.

以这种方式执行。

    String[] array = getResources().getStringArray(R.array.updateInterval);
    System.out.println("--array.length--"+array.length);
    List<String> list = new ArrayList<String>();
    list = Arrays.asList(array);
    ArrayList<String> arrayList = new ArrayList<String>(list);
    arrayList.add("TTS");
    array = arrayList.toArray(new String[list.size()]);
    System.out.println("--array.length--"+array.length);

这篇关于如何以编程方式将项目添加到arrayList中的stringArray?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆