有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在输入int值时从编辑文本中获取计数?

实际上我有一个要求,我需要从编辑文本中获取mobile no,因为计数等于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();
    }
}

当我输入字符或字符串时,它是有效的,但当我输入mobile no means int值时,它不是在祝酒。请帮助我输入手机号码时如何获取计数


共 (2) 个答案

  1. # 1 楼答案

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

       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);
                    }
                }
            }
    
  2. # 2 楼答案

    尝试在TextWatcher中使用afterTextChanged