【问题标题】:Deleting a number in EditText with button click通过单击按钮删除 EditText 中的数字
【发布时间】:2021-09-30 03:28:35
【问题描述】:

我正在制作一个带有删除按钮的计算器。我希望删除按钮一次删除一个元素。

例如,当我按下 DEL btn 时,3 号将从 EditText 中删除。

这是我的 dlt btn 代码

        if (txtResult.length() > 0){
            txtResult = txtResult.getText().Remove(txtResult.length() - 1);
            if (txtResult.equals("")){
                txtResult.setText("0");
            }
        }
    }

.Remove 从 c# 到 android studio java 的等价物是什么? 谢谢。

【问题讨论】:

  • 我想。你缺少其他条件,'txtResult.setText(txtResult);'

标签: android android-studio button


【解决方案1】:

您可以使用substring 删除字符串。
试试这个:

String a = "AAA";
a = a.substring(0, a.length() - 1);
System.out.println(a); // result: AA

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-02
    • 2021-12-01
    • 2016-09-15
    • 2012-05-29
    • 1970-01-01
    • 2011-04-29
    • 1970-01-01
    • 2015-02-03
    相关资源
    最近更新 更多