public class MainActivity extends AppCompatActivity {
EditText Percent, mmolGlic, mgGlic;
double mmol = 0, mg = 0, perc = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Percent = (EditText) findViewById(R.id.percent);
mmolGlic = (EditText) findViewById(R.id.mmol_glic);
mgGlic = (EditText) findViewById(R.id.mg_glic);
/*mmolGlic.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
frommMol();
}
@Override
public void afterTextChanged(Editable s) {
}
});*/
Percent.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
fromPercent();
}
@Override
public void afterTextChanged(Editable s) {
}
});
/*mgGlic.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
frommg();
}
});*/
}
public void frommMol() {
mmol = Double.parseDouble(mmolGlic.getText().toString());
perc = (mmol/10.929) + 2.15;
Percent.setText(String.format( "%.2f", perc ));
}
public void fromPercent(){
perc = Double.parseDouble(Percent.getText().toString());
mmol = (perc - 2.15) * 10.929;
mmolGlic.setText(String.format( "%.2f", mmol ));
mg = (perc*28.7) - 46.7;
mgGlic.setText(String.format( "%.2f", mg ));
}
public void frommg(){
mg = Double.parseDouble(mgGlic.getText().toString());
perc = (mg + 46.7) / 28.7;
Percent.setText(String.format( "%.2f", perc ));
}
}
Goodmorning everyone:)
这是一个连续的问题:Question 1
这是我尝试做的一个示例代码。但我有一些问题。我认为它们中的大多数都是变量的逻辑以及如何在更多的EditTexts中处理输入。例如:
答案 0 :(得分:4)
minDate
答案 1 :(得分:0)
看起来是什么样的,你正在做你的操作,即使你没有任何文本可以使用..我建议,在你执行thefromPercent()之前对editTextView进行空/空检查;操作。希望有所帮助。