Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用if station禁用onCreate方法中的按钮_Java_Android_Android Layout_Disabled Control_Fragment Oncreateview - Fatal编程技术网

Java 如何使用if station禁用onCreate方法中的按钮

Java 如何使用if station禁用onCreate方法中的按钮,java,android,android-layout,disabled-control,fragment-oncreateview,Java,Android,Android Layout,Disabled Control,Fragment Oncreateview,我有一个问题,我想在onCreate方法中禁用一个按钮,请分享在onCreate方法中运行时禁用任何按钮的方法 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_requests_interface); Intent intent = new Intent(t

我有一个问题,我想在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);

    }

}
试试这个:

    Button accButton = (Button) findViewById(R.id.accButton);
    accButton.setEnabled(false);
请注意,在您发布的代码中,您正在使用
findViewbyId()
设置按钮,该按钮应该是
findViewbyId()
(By需要大写)。

在xml中使用
android:enabled=“false”
,或者在code中使用
accButton.setEnabled(false)
此外,最好使用此方法检查是否为数字:

public static boolean isNumeric(String str) {
    try {
        double d = Double.parseDouble(str);
    } catch (NumberFormatException nfe) {
        return false;
    }
    return true;
}
Button Button=(Button)findViewById(R.id.buttonid); 按钮。设置可见性(View.GONE)

这样做:

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

在布局中将其设置为禁用。因此,当您通过
setContentView()
添加它时,您会发现它已被禁用。这样,您就不需要任何额外的代码。除了以后重新启用它之外。您可以使用
enbale
属性通过xml禁用它。选中此项,我可以在onCreate方法中使用if语句吗?因为我必须做一些检查,然后禁用按钮保险。或者您可以编写类似于
accButton.setEnabled(check1&&check2)的代码它只是在将if语句放入它之后给出运行时错误。我可以在onCreate方法中使用if语句吗?因为我必须进行一些检查,然后必须禁用button@bs140200456AqsaAnum是的,我为什么不把if station放进去,现在它给出了运行时间error@bs140200456AqsaAnum包括你的if语句我可以编辑上面的代码吗?如何编辑?我会把我当前的代码放在那里