安卓 : Pass string from xml into string array

标签 android string android-xml

我需要将我在 strings.xml 中创建的字符串传递给具有字符串数组方法的 java 类。我已经创建了字符串,但不知道如何将它传递到数组中

字符串.xml

<string name = "bank">
    <b>Bank</b>
</string>

设备适配器.java

public String[] mThumbNames = {
       getResources().getStringArray(R.string.bank),
        "Hostel",
        "GYM",
        "Library",
        "Sports",
        "Guest House"

};

最佳答案

public class FacilityAdapter extends BaseAdapter {

    private String[] mThumbNames;

    public FacilityAdapter(Context c){
        mThumbNames = new String[] {c.getString(R.string.bank), "Hostel", "GYM"};
    }

    //...

}

关于安卓 : Pass string from xml into string array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35943019/

相关文章:

android - 在我选择选项卡之前加载进度条

Python:减少(字符串列表)-> 字符串

android - XML android 中带有圆底的背景图像

android - Kotlin在与 Activity 不同的布局上更新textview的文本

android - ImageView 未按预期填充父级

android - bindService的疑惑

android - 我无法将 Android 项目从 Delphi 10.4 迁移到 Delphi 11.1

c++ - 在 Android 上进行实时图形编程的最佳语言是什么?

php - PHP爆炸并可能逃脱分隔符

java - 将字符串拆分为单词数组以便再次调用