我是新手,我想知道如果我的EditText是空的可以启用或禁用botton。但是当EditText为空时,按钮将继续显示为启用。这是我的代码。知道是否EditText为空
if((getActivity().findViewById(R.id.textcodigo)).toString().matches("")){
Button aceptar= (Button) getActivity().findViewById(R.id.aceptar);
aceptar.setEnabled(false);
}
我使用的片段,它说,该方法的getText()是未定义 – user3383415
(只是出于好奇):不会'findViewById(R.id.textcodigo))的getText ().toString()。length == 0'会更快吗? –
我不知道它是更快或不是,但这是另一种方式来检查 – tyczj