Thursday, 19 September 2013

Looking up enum label by value

Looking up enum label by value

I have the following enum in my java android application:
static enum PaymentType
{
Scheme(0), Topup(1), Normal(2), Free(3), Promotion(4), Discount(5),
Partial(6),
Refund(7), NoShow(8), Prepay(9), Customer(10), Return(11), Change(12),
PettyCash(13),
StateTax(14), LocalTax(15), Voucher(16), Membership(17), Gratuity(18),
Overpayment(19),
PrepayTime(20), HandlingFee(21);
private int value;
private PaymentType(int i) {
value = i;
}
public int getValue() {
return value;
}
}
I use this enum alot to find out the integer value of one of these string
labels, for example int i = Lookups.PaymentType.Voucher.getValue();.
How can I do this the other way around? I have an integer value from a
database and I need to find which string that corresponds to.

No comments:

Post a Comment