我有一個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
檢查我編輯的答案 –