我有一个enum
类为两种类型的数学值,它们是,AMOUNT
和PERCENTAGE
。如何为ENUM设置文本并支持多种语言?
这两个是单选按钮,取决于用户选择的单选按钮。文本被相应地设置。
直到现在,我的应用程序只有一种语言,但现在我已经使它成为多语言。如何根据语言设置ENUM
的文字?
这是我enum
:
public enum DiscountTypeEnum {
AMOUNT,
PERCENTAGE;
private DiscountTypeEnum() {
}
}
我想基于什么discountType
用户选择要设置的字符串,
for (DiscountTypeEnum discountType : DiscountTypeEnum.values()) {
RadioButton discountTypeButton = new RadioButton(getContext());
// below is where I need to set the text from string resource file
// setText(R.string.AMOUNT) or setText(R.string.PERCENTAGE)
discountTypeButton.setText(discountType.name());
discountTypes.addView(discountTypeButton);
}
我ENUM是一个Java类,而不是机器人。在那种情况下,我怎样才能使用多语言字符串? – baabidi
检查我编辑的答案 –