1

エディットテキストの文字を1つずつ削除したい。私はかなり研究しましたが、いくつかの問題があります、アドバイスしてください。これは私のサンプルコードです。

削除ボタンを作成しました"ImageButton buttonDelete;"// XML imageButton1 。編集テキストは"EditText display;"

display = (EditText) findViewById(R.id.editText1);
        buttonDelete.setOnClickListener(new View.OnClickListener()
        {
             public void onClick() 
             {
               // Get edit text characters
                String textInBox = display.getText():
                //Remove last character//
                String newText = textInBox.substring(0, textInBox.length()-1);
                // Update edit text
                display.setText(newText);
4

2 に答える 2

3

これを試して:

// 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); 
}
于 2012-07-07T11:04:59.933 に答える