高度转换 - 厘米到英尺和英寸(反之亦然)(Height Conversion - cm to feet and inches (and vice versa))
我有一个编辑文本,用户可以用厘米以及英尺+英寸输入他的身高,例如。 5'11“。我有一个目标单位的切换按钮,所以我希望当用户选择厘米时,它应该将输入的文本从英尺+英寸转换为厘米,反之亦然。现在当我将高度转换为厘米,它最后加上“\”“。 我认为这是因为我已经提出了文本观察者,当计数达到3时,最后添加“\”。
public void onClick(View view) { switch (view.getId()) { case R.id.btnCm: toggleHeightButton(R.id.btnCm,R.id.btnFeet,false); convertToCentimeter(enter_height); break; case R.id.btnFeet: toggleHeightButton(R.id.btnFeet,R.id.btnCm,true); enter_height.addTextChangedListener(new CustomTextWatcher(enter_height)); break; case R.id.btnKg: toggleweightButton(R.id.btnKg,R.id.btnpound,false); break; case R.id.btnpound: toggleweightButton(R.id.btnpound,R.id.btnKg,true); break; } } public class CustomTextWatcher implements TextWatcher { private EditText mEditText; public CustomTextWatcher(EditText enter_height) { mEditText = enter_height; } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { } public void afterTextChanged(Editable s) { int count = s.length(); String str = s.toString(); if (count == 1) { str = str + "'"; } else if (count == 2) { return; } else if (count == 3) { str = str + "\""; } else if ((count > 4) && (str.charAt(str.length() - 1) != '\"') ){ str = str.substring(0, str.length() - 2) + str.charAt(str.length() - 1) + "\""; } else { return; } mEditText.setText(str); mEditText.setSelection(mEditText.getText().length()); } }
I have an edit text in which the user can enter his height in centimeters as well as in feet+inches, eg. 5'11". I have a toggle button for the target unit, so I want that when the user selects centimeters, it should convert the entered text from feet+inches into centimeters, and vice versa. Now when I am converting the height to centimeters it's adding "\"" at the end. I think it's because of the text watcher I have put which add "\"" at the end when count is reaching to 3.
public void onClick(View view) { switch (view.getId()) { case R.id.btnCm: toggleHeightButton(R.id.btnCm,R.id.btnFeet,false); convertToCentimeter(enter_height); break; case R.id.btnFeet: toggleHeightButton(R.id.btnFeet,R.id.btnCm,true); enter_height.addTextChangedListener(new CustomTextWatcher(enter_height)); break; case R.id.btnKg: toggleweightButton(R.id.btnKg,R.id.btnpound,false); break; case R.id.btnpound: toggleweightButton(R.id.btnpound,R.id.btnKg,true); break; } } public class CustomTextWatcher implements TextWatcher { private EditText mEditText; public CustomTextWatcher(EditText enter_height) { mEditText = enter_height; } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { } public void afterTextChanged(Editable s) { int count = s.length(); String str = s.toString(); if (count == 1) { str = str + "'"; } else if (count == 2) { return; } else if (count == 3) { str = str + "\""; } else if ((count > 4) && (str.charAt(str.length() - 1) != '\"') ){ str = str.substring(0, str.length() - 2) + str.charAt(str.length() - 1) + "\""; } else { return; } mEditText.setText(str); mEditText.setSelection(mEditText.getText().length()); } }
原文:https://stackoverflow.com/questions/39423348
最满意答案
您可以使用
geom_rect()
并使用plus_
和minus_
变量作为max
和min
坐标(将数据命名为df
)来实现它。ggplot(df,aes(xmin=minus_age,xmax=plus_age,ymin=minus_error,ymax=plus_error))+ geom_rect(fill="green",color="black")
You can achieve it with
geom_rect()
and using yourplus_
andminus_
variables asmax
andmin
coordinates (named your data asdf
).ggplot(df,aes(xmin=minus_age,xmax=plus_age,ymin=minus_error,ymax=plus_error))+ geom_rect(fill="green",color="black")
相关问答
更多-
Matplotlib散点图图例(Matplotlib scatter plot legend)[2024-01-16]
2D散点图 使用matplotlib.pyplot模块的scatter方法应该可以工作(至少在matplotlib 1.2.1中使用Python 2.7.5),如下面的示例代码所示。 此外,如果您正在使用散点图,则在图例调用中使用numpoints=1而不是numpoints=1 ,以便每个图例条目只有一个点。 在下面的代码中,我使用了随机值,而不是一遍又一遍地绘制相同的范围,使所有的图都可见(即不相互重叠)。 import matplotlib.pyplot as plt from numpy.rando ... -
嗯,当然它使用一个符号。 你告诉它了! 如果您希望能够专门指定两个标记,请删除MARKERATTR=(symbol=代码,或使用MARKERCHAR使其来自变量或属性地图数据集( DATTRMAP )以指定它,或者使用颜色。 这里有一些例子: *Using MARKERCHAR; data cars; set sashelp.cars; if make = 'Dodge' then marker_char = '+'; else if make = 'Chrysler' then marker_ ...
-
如何为每个标签创建只有一个符号的散点图图例?(How to create a scatter plot legend with only one symbol for each label?)[2022-10-12]
在legend命令中,您可以使用scatterpoints选项: ax.legend(loc=0, scatterpoints = 1) 对于正常情节,它是选项numpoints 。 在这里,您可以找到有关图例的关键字参数的更多信息: http : //matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.legend In the legend command you can use the scatterpoints opti ... -
融化数据,然后使用ggplot和facet。 library("ggplot2") library("reshape2") #dummy data df <- data.frame(x=1:10, a=runif(10), b=runif(10), c=runif(10)) #melt your data df_melt <- melt(df,"x") #scatterplot per group g ...
-
绘制散点图时不需要为数据声明多个变量(Creating a scatter plot in plotly without declaring multiple variables for the data)[2022-05-26]
假设你的数据是在一个对象数组中,你可以使用下面的方法。 迭代一组condition var conditions = new Set(data.map(a => a.condition)); conditions.forEach(function(condition) { var newArray = data.filter(function(el) { return el.condition == condition; }); }) 将id映射到x并将value映射到y ... -
没有配置选项来执行此操作。 正如你所说,困难的方法是在渲染器的帮助下实现它。 您可以使用颜色和大小配置各个点: data: [{ x: 161.2, y: 51.6, marker: { radius: 15, fillColor: 'rgb(255, 0, 0)' } }] 但连接两个标记的线没有任何单独的设置。 There is no configuration option to do this. The difficult way ...
-
R中的几个图(特定变量与其他变量的散点图)(several plots (scatter plot of a specific variable vs other variables) in R)[2022-03-30]
由于您使用ggplot2标记了您的问题,我将假设您对ggplot2解决方案感兴趣。 rock <- data.frame(area = sample(1:100, 10, replace = TRUE), peri = sample(1:100, 10, replace = TRUE), shape = sample(1:100, 10, replace = TRUE), perm = ... -
将数据熔化为长形式,以便将所有四个变量的数据传递给一个美学: df_melt <- reshape2::melt(df, id.var = 'ZIP.Code') # or df_melt <- tidyr::gather(df, variable, value, Graduation.Rate:Pot_Holes) df_melt # ZIP.Code variable value # 1 60605 Graduation.Rate 0.00876233 # ...
-
如何使用Scatter Plot highchart绘制下图?(How to draw following graph using Scatter Plot highchart?)[2023-02-10]
使用renderer.path绘制一条线。 您可以在加载事件上绘制线条并在重绘事件上重绘它。 events: { load: function() { var point = this.series[0].points[0], { plotX: x, plotY: y } = point; point.path = this.renderer.path() .add(point.ser ... -
创建散点图,其中符号高度/宽度由2个变量控制(Creating scatter plot where symbol height/width is controlled by 2 variables)[2023-09-10]
您可以使用geom_rect()并使用plus_和minus_变量作为max和min坐标(将数据命名为df )来实现它。 ggplot(df,aes(xmin=minus_age,xmax=plus_age,ymin=minus_error,ymax=plus_error))+ geom_rect(fill="green",color="black") You can achieve it with geom_rect() and using your plus_ and minus_ variabl ...