subString是String的一个方法,格式为:

public String substring(int beginIndex, int endIndex) 
返回一个新字符串,它是此字符串的一个子字符串。
该子字符串从指定的 beginIndex 处开始,一直到索引 endIndex - 1 处的字符。因此,该子字符串的长度为 endIndex-beginIndex。 
 
示例: 
截取str字符串的第2个和第三个。
String str = "123456789"; str =str.substring(1,3
结果:str="23"
 
在Android应用中,删除按键的程序如下:
button_15.setOnClickListener(new View.OnClickListener() {   
 
  @Override
  public void onClick(View v) {
     editText=(EditText)findViewById(R.id.editText);
     textContent=editText .getText().toString();
 
     if(!"" .equals(textContent)){
     //文本框中内容非空时执行删除操作
       text=textContent .substring(0, textContent.length()-1);
       editText.setText(text );
       editText.setSelection(text .length());
 
     }
  }
});
 
 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-09
  • 2022-12-23
  • 2022-01-01
  • 2021-06-12
  • 2022-01-11
  • 2021-08-08
相关资源
相似解决方案