简体   繁体   English

将项目添加到资源文件

[英]Add item to resource file

How to programmatically add item to strings.xml for spinner's string-array? 如何以编程方式将项目添加到spinner的字符串数组的strings.xml中?

<Spinner
            android:id="@+id/tags"
            android:spinnerMode="dialog"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:entries="@array/tags" />    

strings.xml strings.xml

<string-array name="tags">
    <item>item1</item>
    <item>item2</item>
    <item>item3</item>
    <item>item4</item>
</string-array>>

You can't add data to application resources programmatically. 您不能以编程方式将数据添加到应用程序资源。 Resources are part of compiled, packed and signed APK package and therefore can't be modified. 资源是已编译,打包和签名的APK包的一部分,因此无法进行修改。 What are you trying to achieve? 您想达到什么目的?

You can't add things to resources programmatically. 您不能以编程方式将事物添加到资源中。 But a Spinner doesn't need to go off a resource file. 但是Spinner不需要关闭资源文件。 Use an in memory list of items, and modify that. 使用内存中的项目列表,然后进行修改。

If try to add data in spinner programmtically. 如果尝试以编程方式在微调器中添加数据。

there is only one way use database like #firebase which update realtime data. 只有一种方法可以使用像#firebase这样的数据库来更新实时数据。

"without database it not possible." “没有数据库是不可能的。”

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

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