小编Ish*_*han的帖子

Android中的TypeArray - 如何在xml中存储自定义对象并检索它们?

我有一个类似的课程

public class CountryVO {
    private String countryCode;
    private String countryName;
    private Drawable countryFlag;

    public String getCountryCode() {
        return countryCode;
    }
    public void setCountryCode(String countryCode) {
        this.countryCode = countryCode;
    }
    public String getCountryName() {
        return countryName;
    }
    public void setCountryName(String countryName) {
        this.countryName = countryName;
    }
    public Drawable getCountryFlag() {
        return countryFlag;
    }
    public void setCountryFlag(Drawable countryFlag) {
        this.countryFlag = countryFlag;
    }
}
Run Code Online (Sandbox Code Playgroud)

并希望将此类的对象存储在Android的TypeArray xml中

<resources>
    <array name="custom_arr">
        <item>
            <countryName>Albania</countryName>
            <countryCode>al</countryCode>
            <countryFlag>@drawable/al</countryFlag>
        </item>
        <item>
            <countryName>Algeria</countryName>
            <countryCode>dz</countryCode>
            <countryFlag>@drawable/dz</countryFlag>
        </item>
        <item>
            <countryName>American …
Run Code Online (Sandbox Code Playgroud)

xml android custom-component typedarray

20
推荐指数
3
解决办法
2万
查看次数

标签 统计

android ×1

custom-component ×1

typedarray ×1

xml ×1