在编辑界面,如果正在编辑,就删除编辑的内容。如果编辑的内容为空,按下返回键就返回上一界面,请问该如何实现?
修改 Activity.java 中 onKeyUp 为如下:
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.ECLAIR) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking() && !event.isCanceled()) {
if (isResumed()) {
View decorView = this.getWindow().getDecorView();//MTK modifyBegin
if (decorView != null) {
View focus = decorView.findFocus();
if (focus!=null && focus instanceof EditText) {
EditText editText = (EditText)focus;
CharSequence text = editText.getText();
if (text!=null && text.length()>0) {
editText.setText("");
return true;
}
}
}
onBackPressed(); //MTK modify END
return true;
} else {
Log.v(TAG, "Tracking Key Up, activity is resumed: " + isResumed());
// Fix sub activity of tab activity which isn't in resumed state
// Return false means didn't handle this key event
return false;
}
/// @}
}
}
return false;
}