gpt4 book ai didi

android 将小时转换为分钟

转载 作者:行者123 更新时间:2023-11-29 21:11:47 25 4
gpt4 key购买 nike

    et1 = (EditText) findViewById(R.id.et1);
et2 = (EditText) findViewById(R.id.et2);

floatET1 = Float.parseFloat(et1.getText().toString());
floatET2 = Float.parseFloat(et2.getText().toString());

et1.setOnFocusChangeListener(new OnFocusChangeListener() {

public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
float sonuc1 = floatET2 * 60;
et2.setText(sonuc1);
}
}
});

et2.setOnFocusChangeListener(new OnFocusChangeListener() {

public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
float sonuc2 = floatET1 / 60;
et1.setText(sonuc2);

当我点击 EditText (et2) 然后我想计算到分钟,当我点击 EditText (et1) 然后转换为小时......但我不工作:/

最佳答案

这会做你想做的事,尽管你可能想用 toast 消息或其他东西来通知用户,而不是在输入值不是有效字符串时静静地什么也不做。

et1 = (EditText) findViewById(R.id.et1);
et2 = (EditText) findViewById(R.id.et2);

et1.setOnFocusChangeListener(new OnFocusChangeListener() {

public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
try {
floatET2 = Float.parseFloat(et2.getText().toString());
} catch (NumberFormatException e) {
}
float sonuc1 = floatET2 * 60;
et1.setText(String.valueOf(sonuc1));
}
}
});

et2.setOnFocusChangeListener(new OnFocusChangeListener() {

public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
try {
floatET1 = Float.parseFloat(et1.getText().toString());
} catch (NumberFormatException e) {
}
float sonuc2 = floatET1 / 60;
et2.setText(String.valueOf(sonuc2));
}
}
});

关于android 将小时转换为分钟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22552876/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com