clearButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
clear();
Toast.makeText(HomeSafeActivity.this, "Normal Press", Toast.LENGTH_LONG).show();
});
clearButton.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Toast.makeText(HomeSafeActivity.this, "Long preess", Toast.LENGTH_LONG).show();
yourEditText.setText("");
return true;
}
});
public void clear(){
Editable editableText = yourEditText.getEditableText();
int length = editableText.length();
if (length > 0) {
editableText.delete(length - 1, length);
}
}
明確的最後一個字符,並清除所有文字onlongclick按鈕。 – Android
謝謝,它的工作原理! – Nmaster88
最受歡迎:) – Android