我认为描述我的问题的最佳方式是先描述我在做什么。
我有一个带有 3 个列表选择选项(启动列表视图的按钮)的简单活动。每个 ListPicker 在 ListView 中有 8 个项目。
Listview中的每一个Item,我们称之为Name的值,都有对应的Address和Phone。
所以这里是我正在使用的常量的例子
public final String GROUP_1_VENUE_1_NAME = "1name1";
public final String GROUP_1_VENUE_1_ADDRESS = "1address1";
public final String GROUP_1_VENUE_1_PHONE = "1phone1";
public final String GROUP_1_VENUE_2_NAME = "1name2";
public final String GROUP_1_VENUE_2_ADDRESS = "1address2";
public final String GROUP_1_VENUE_2_PHONE = "1phone2";
public final String GROUP_1_VENUE_3_NAME = "1name3";
public final String GROUP_1_VENUE_3_ADDRESS = "1address3";
public final String GROUP_1_VENUE_3_PHONE = "1phone3";
.....
public final String GROUP_2_VENUE_1_NAME = "2name1";
public final String GROUP_2_VENUE_1_ADDRESS = "2address1";
public final String GROUP_2_VENUE_1_PHONE = "2phone1";
public final String GROUP_2_VENUE_2_NAME = "2name2";
public final String GROUP_2_VENUE_2_ADDRESS = "2address2";
public final String GROUP_2_VENUE_2_PHONE = "2phone2";
....
public final String GROUP_3_VENUE_1_NAME = "3name1";
public final String GROUP_3_VENUE_1_ADDRESS = "3address1";
public final String GROUP_3_VENUE_1_PHONE = "3phone1";
public final String GROUP_3_VENUE_2_NAME = "3name2";
public final String GROUP_3_VENUE_2_ADDRESS = "3address2";
public final String GROUP_3_VENUE_2_PHONE = "3phone2";
...
所以从listPicker中挑选了一个项目,现在我想评估结果
我有 3 个字符串需要设置;姓名、地址和电话
所以现在我有这样的东西......
if (selection.equals(GROUP_1_VENUE_1_NAME) {
name = GROUP_1_VENUE_1_NAME;
address = GROUP_1_VENUE_1_ADDRESS;
phone = GROUP_1_VENUE_1_PHONE;
} else if (selection.equals(GROUP_1_VENUE_2_NAME) {
name = GROUP_1_VENUE_2_NAME;
address = GROUP_1_VENUE_2_ADDRESS;
phone = GROUP_1_VENUE_2_PHONE;
} else if .....
等等等等。
所以,这是我的问题。有没有更简单的方法可以让我评估选择是否等于 NAME CONSTANTS 之一,如果是,设置相应的值?