小编dru*_*nii的帖子

使用警报对话框摇动动画(如果无效信息摇动编辑文本并且不要关闭)

所以我有一个对话框,用户在其中输入数据,这里是用户的年龄。所以我希望当/如果用户将 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)

android android-layout

2
推荐指数
1
解决办法
8327
查看次数

标签 统计

android ×1

android-layout ×1