我目前使用两个不同的片段来显示半个列表:
片段1
if (i%2 != 1) {
Show first half List;
}
片段2
if (i%2 == 1) {
Show second half List;
}
但是我希望用一个叫做两次的片段来清理一些东西:
片段
prefOperator = bundle.getInt(WHICH_HALF);
if (prefOperator == 1) OPERATOR = "!=";
else if (prefOperator == 2) OPERATOR = "==";
if (i%2 OPERATOR 1) {
Show List;
}
我想这是可能的,但找不到怎么做。
答案 0 :(得分:4)
不要更改运算符,而是将您要比较的值更改为:
// Since WHICH_HALF has value 1 or 2, we will subtract one.
int prefOperator = bundle.getInt(WHICH_HALF) - 1;
if (i%2 == prefOperator) {
// Show first half of list
} else {
// Show second half of list
}