所以我有一个对话框,用户在其中输入数据,这里是用户的年龄。所以我希望当/如果用户将 edittext 留空时,edittext 将执行像 api 演示中那样的摇动动画。到目前为止,当输入无效信息时,我无法让对话框不关闭。谢谢。
mInflater = (LayoutInflater) Information.this.getSystemService(LAYOUT_INFLATER_SERVICE);
mLayout = mInflater.inflate(R.layout.agedialog, null);
mAgeEditText = (EditText) mLayout.findViewById(R.id.AgeEditText);
mAgeResultTextView = (TextView) findViewById(R.id.AgeResultTextView);
final Animation shake = AnimationUtils.loadAnimation(Information.this, R.anim.shake);
mInputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mInputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
new AlertDialog.Builder(Information.this).setView(mLayout).setTitle(R.string.EnterYourAge)
.setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
mInputManager.hideSoftInputFromWindow(mAgeEditText.getWindowToken(), 0);
if (TextUtils.isEmpty(mAgeEditText.getText())) {
mAgeEditText.startAnimation(shake);
// here the dialog dismisses even if I call startAnimation
}
else {
HelperClass.getInstance().setAge(Integer.parseInt(mAgeEditText.getText().toString()));
mAgeResultTextView.setText(HelperClass.getInstance().getAge());
}
}
}).setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) …Run Code Online (Sandbox Code Playgroud)