我在array.xml中有两个数组,一个数组包含以英寸为单位的值,另一个数组包含以厘米为单位的相应值。我希望当用户选择以英寸为单位的某个值时,我可以以厘米为单位显示相应的值。 现在我正在尝试使用标准公式转换,但这并没有给我确切的价值。 这是我的代码:
// if user changed the Height from foot inch to centimeters
if(Height_pref.equals(HEIGHT_UNIT)){
CharSequence []changedHeight = changeHeightCms();
heightPicker.setValues(changedHeight);
height_text.setText(getString(R.string.HeightCms));
}
//method to change height from ft'in" to cms
public CharSequence[] changeHeightCms(){
//final double[] weightLbs = new double[200];
final ArrayList<CharSequence> ChangeheightArray = new ArrayList<CharSequence>();
for (int index = 3; index < 7; index++) {
for (int index1 = 0; index1 < 12; index1++) {
float footinch = ((index*12)+index1);
int centimeters = Math.round((float) (footinch*2.54));
ChangeheightArray.add(centimeters + "");
if (index == 6 && index1 == 4) {
break;
}
}
}
CharSequence[] height1 = new CharSequence[ChangeheightArray.size()];
final CharSequence[] HeightCmsArray = ChangeheightArray.toArray(height1);
return HeightCmsArray;
}
任何人都可以告诉我,如果我对这些值进行硬编码,那么我该如何显示转换?
答案 0 :(得分:-2)
使用此代码......
corelayouts:CarouselViewDots.CarouselViews
此转换链接: - http://www.metric-conversions.org/length/feet-to-centimeters.htm
享受编码.....