我有一个以英尺为单位的高度值列表。如果用户将高度指标从英寸英寸更改为厘米,则列表会以厘米为单位显示所有值。
这是我的英尺高度代码:
HorizontalPicker heightPicker = (HorizontalPicker) view.findViewById(R.id.heightPicker);
final ArrayList<CharSequence> heightArray = new ArrayList<CharSequence>();
for (int index = 3; index < 7; index++) {
for (int index1 = 0; index1 < 12; index1++) {
heightArray.add(index + "." + index1 + "\"");
if (index == 6 && index1 == 4) {
break;
}
}
}
CharSequence[] height1 = new CharSequence[heightArray.size()];
final CharSequence[] height = heightArray.toArray(height1);
heightPicker.setValues(height);
heightPicker.setOnItemSelectedListener(new HorizontalPicker.OnItemSelected() {
@Override
public void onItemSelected(int index) {
double heightInt = 0;
try {
heightInt = Double.parseDouble(trimLastChar(height[index].toString()));
} catch (NumberFormatException ex) {
ex.printStackTrace();
}
userProfile.setHeight(heightInt);
}
});
有人可以帮帮我吗?