开发学院手机开发Android 开发 Android editText 输入字数限制 阅读

Android editText 输入字数限制

 2010-04-21 06:53:00 来源:WEB开发网   
核心提示://输入框限制输入字数editText.addTextChangedListener(new TextWatcher(){private CharSequence temp;private boolean isEdit = true;@Overridepublic void afterTextChanged(Edita

//输入框限制输入字数

editText.addTextChangedListener(new TextWatcher(){

private CharSequence temp;

private boolean isEdit = true;

@Override

public void afterTextChanged(Editable s) {

if(temp.length()>Constant.TEXT_MAX){

isEdit = false;

s.delete(temp.length()-1,temp.length());

editText.setText(s);

}

}

@Override

public void beforeTextChanged(CharSequence s, int arg1,int arg2, int arg3) {

temp = s;

}

@Override

public void onTextChanged(CharSequence s, int arg1, int arg2,int arg3) {

if(isEdit == false){

Toast.makeText(KaguProductActivity.this, R.string.edit_content_limit, Toast.LENGTH_SHORT)

.show();

Editable etext = editText.getText();

int pos = etext.length();

Selection.setSelection(etext,pos);

}

}

});

Tags:Android editText 输入

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
更多精彩
    赞助商链接

    热点阅读
      焦点图片
        最新推荐
          精彩阅读