【问题标题】:How to get count from edit text while entering int values?如何在输入 int 值时从编辑文本中获取计数?
【发布时间】:2015-01-28 10:03:47
【问题描述】:

实际上我有一个需求,我需要从编辑文本中获取移动号码,并且由于计数等于 10,所以它必须调用 Intent。所以我使用“addTextChangedListener”。

et_mobile_no.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if(count == 10){
                Toast.makeText(getApplicationContext(),
                        "Count is " + count, Toast.LENGTH_SHORT).show();
    }
}

当我输入字符或字符串时它可以工作,但是当我输入移动设备时,它并不意味着 int 值,它不会给大家敬酒。请帮助我如何在输入手机号码时获得计数。 ????

【问题讨论】:

  • 检查您是否使用日志获取字符序列中的数字
  • 实际上,当我输入字符串时,会显示 toast,但是当我输入 int 值时,不会显示 toast...

标签: java android android-edittext android-toast


【解决方案1】:

尝试在 TextWatcher 中使用 afterTextChanged

【讨论】:

    【解决方案2】:

    是的,这有点棘手。我得到了答案。这是答案。

       et_mobile_no.addTextChangedListener(new TextWatcher() {
    
            @Override
            public void onTextChanged(CharSequence s, int start, int before,
                    int count) {
                if (s.length() == 10) {
                    if (et_mobile_no.getText().toString().equals("9920263416")) {
    
                        Intent i = new Intent(SplashActivity.this,
                                CustomerLookUp.class);
                        startActivity(i);
                    } else {
                        hided_views.setVisibility(View.VISIBLE);
                    }
                }
            }
    

    【讨论】:

    • 不管放在哪里,只要是在你初始化你的edittext之后
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-21
    • 1970-01-01
    • 1970-01-01
    • 2019-07-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多