Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 删除或退格功能。我创建了一个按钮,但无法在edittext中执行删除/退格操作_Android_Android Edittext_Backspace - Fatal编程技术网

Android 删除或退格功能。我创建了一个按钮,但无法在edittext中执行删除/退格操作

Android 删除或退格功能。我创建了一个按钮,但无法在edittext中执行删除/退格操作,android,android-edittext,backspace,Android,Android Edittext,Backspace,我想逐个删除编辑文本中的字符。我已经做了很多研究,但是有一些问题,请提出建议。这是我的示例代码 我创建了一个删除按钮“ImageButtonDelete;”//XML imageButton1 我的编辑文本是“编辑文本显示;” 试试这个: // Get edit text characters String textInBox = display.getText().toString(); if(textInBox.length() > 0) { //Remove last cha

我想逐个删除编辑文本中的字符。我已经做了很多研究,但是有一些问题,请提出建议。这是我的示例代码

我创建了一个删除按钮
“ImageButtonDelete;”//XML imageButton1
我的编辑文本是
“编辑文本显示;”

试试这个:

// Get edit text characters 
String textInBox = display.getText().toString(); 
if(textInBox.length() > 0)
{
  //Remove last character// 
  String newText = textInBox.substring(0, textInBox.length()-1); 
  // Update edit text 
  display.setText(newText); 
}

嗨,在这里和那里做了一些编辑之后,我设法让它工作了。。谢谢你的朋友!!请在你的回答中加上一些解释。只有过帐代码可能会令人困惑。
// Get edit text characters 
String textInBox = display.getText().toString(); 
if(textInBox.length() > 0)
{
  //Remove last character// 
  String newText = textInBox.substring(0, textInBox.length()-1); 
  // Update edit text 
  display.setText(newText); 
}
BtonBackSpace.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            String bs = null;
            if(Tfield.getText().length()>0){
                StringBuilder Strb = new StringBuilder(Tfield.getText());
                Strb.deleteCharAt(Tfield.getText().length() - 1);
                bs = Strb.toString();
                Tfield1.setText(bs );

            }