EditText上最小长度和放大器;启动新活动 [英] EditText Minimum Length & Launch New Activity

查看:138
本文介绍了EditText上最小长度和放大器;启动新活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一对夫妇就在Android上的EditText功能查询。

I have a couple of queries regarding the EditText function in Android.

首先,是它可以设置字符的最小数目在外地的EditText?我知道,有一个

First of all, is it possible to set a minimum number of characters in the EditText field? I'm aware that there is an

android:maxLength="*"

然而,出于某种原因,你不能有

however for some reason you can't have

android:minLength="*"

另外,我想知道是否有可能推出$ P $后,一个新的活动pssing的输入查询数据到现场的EditText弹出时,我们键盘上的回车键?如果是的话,可能会有人告诉我怎么样?

Also, I was wondering if it is possible to launch a new activity after pressing the enter key on the keyboard that pops us when inputing data into the EditText field? And if so, could someone show me how?

感谢您的帮助,您可以提供关于两个问题:)

Thanks for any help you could offer regarding either question :)

推荐答案

要应对输入键在编辑栏,并通知用户,如果他们还没有进入足够的文字:

To respond to an enter key in your edit field and notify the user if they haven't entered enough text:

EditText myEdit = (EditText) findViewById(R.id.myedittext);
    myEdit.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                if (myEdit.getText().length() < minLength) {
                    Toast.makeText(CurrentActivity.this, "Not enough characters", Toast.LENGTH_SHORT);
                } else {
                    startActivity(new Intent(CurrentActivity.this, ActivityToLaunch.class);
                }
                return true;
            }
            return false;
        }
    });

有没有简单的方法来强制最小长度作为字段编辑。你会检查输入的每一个字符的长度,然后扔出去的按键,当用户试图删除过去的最低水平。这是pretty的凌乱这就是为什么没有内置的方式做到这一点。

There's no simple way to force a minimum length as the field is edited. You'd check the length on every character entered and then throw out keystrokes when the user attempt to delete past the minimum. It's pretty messy which is why there's no built-in way to do it.

这篇关于EditText上最小长度和放大器;启动新活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆