代码之家  ›  专栏  ›  技术社区  ›  bs140200456 Aqsa Anum

如何使用if statment[duplicate]禁用onCreate方法中的按钮

  •  -2
  • bs140200456 Aqsa Anum  · 技术社区  · 7 年前

    我有一个问题,我想在onCreate方法中禁用一个按钮,请分享在运行时在onCreate方法中禁用任何按钮的方法。

     @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_requests_interface);
    
    
      Intent intent = new Intent(this, AdminPopup.class);
        startActivity(intent);
    
    
        String fName = getIntent().getStringExtra("fName");
        TextView tfName = (TextView)findViewById(R.id.fName);
        tfName.setText(fName);
        String vuEmail = getIntent().getStringExtra("VUEmail");
        TextView tEmail = (TextView)findViewById(R.id.vuEmail);
        tEmail.setText(vuEmail);
    
        EditText vuEmailTest = (EditText)findViewById(R.id.vuEmail);
        String email = vuEmailTest.getText().toString();
        String str = email.substring(0,2);
        if(str.equals("bc")){
            String str2 = email.substring(3,9);
            boolean digitsOnly = TextUtils.isDigitsOnly(str2);
            if (digitsOnly){
                Button accButton = (Button)findViewById(R.id.accButton);
    
            }
        }
        else{
            Button accButton = (Button)findViewById(R.id.accButton);
    
        }
    
    }
    
    4 回复  |  直到 7 年前
        1
  •  1
  •   Lakshmi Priya Vikram    7 年前

    Button Button=(Button)findViewById(R.id.buttonid); 按钮。设置可见性(视图。消失);

        2
  •  1
  •   Ben P.    7 年前

        Button accButton = (Button) findViewById(R.id.accButton);
        accButton.setEnabled(false);
    

    请注意,在您发布的代码中,您将按钮设置为 findViewbyId() findViewById() (By需要大写)。

        3
  •  1
  •   SiSa    7 年前

    使用 android:enabled="false" accButton.setEnabled(false)

    public static boolean isNumeric(String str) {
        try {
            double d = Double.parseDouble(str);
        } catch (NumberFormatException nfe) {
            return false;
        }
        return true;
    }
    
        4
  •  1
  •   Elysian Apps    7 年前

    执行以下操作:

    Button b = (Button) findViewById(R.id.mybutton);
    b.setEnabled(false);