mmEditText = (EditText) findViewById(R.id.yyy);
mmEditText.setFocusable(true);
mmEditText.setFocusableInTouchMode(true);
mmEditText.requestFocus();
mmEditText.findFocus();
mmEditText.setText("");
mmEditText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
if(mmEditText.getText().toString().trim().equals("")){
System.out.println("清空");
}else{
if(delayRun!=null){
//每次editText有变化的时候,则移除上次发出的延迟线程
handler.removeCallbacks(delayRun);
}
//延迟800ms,如果不再输入字符,则执行该线程的run方法
handler.postDelayed(delayRun, 200);
}
}
});
、
private Handler handler = new Handler();
/** 延迟线程,看是否还有下一个字符输入 */
private Runnable delayRun = new Runnable() {
@Override
public void run() {
//在这里调用服务器的接口,获取数据
Toast.makeText(MainActivitysss.this, mmEditText.getText().toString().trim(), 100).show();
Namespace = mmEditText.getText().toString().trim();
long num = Long.parseLong(Namespace);//int的最大位数为214.299的10进制转换会报错,要用long
String cardId = Long.toHexString(num).toUpperCase();//10进制转16进制并且转大写
cardNO = cardId;
mmEditText.setText("");
}