edittext visible意味着我如何检查android中的if条件

我已经检查过我的edittext在android中可见或不可见。

现在我必须检查条件是。,

  1. 如果我的edittext可见,则表示如何插入数据。
  2. 如果我的edittext消失了意味着我如何插入另一个数据。

这是我的代码,如果我必须选中复选框意味着edittext是不可见的,否则edittext是可见的。:

chkIos = (CheckBox) findViewById(R.id.addresscheckbox); chkIos.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (((CheckBox) v).isChecked()) { S_address = (TextView)findViewById(R.id.address1); S_address.setVisibility(View.GONE); Saddress = (EditText)findViewById(R.id.tf_address1); Saddress.setVisibility(View.GONE); } else { S_address = (TextView)findViewById(R.id.address1); S_address.setVisibility(View.VISIBLE); Saddress = (EditText)findViewById(R.id.tf_address1); Saddress.setVisibility(View.VISIBLE); if(!(Saddress.getText().toString().length() == 0)){ showAlertbox(" Shipping Address is Required!!"); } } 

下面的代码是。,如果我的edittext是可见的意味着插入saddr值。另外插入baddr值。我可以检查条件。

下面显示错误:VISIBLE无法解析为变量。

  if(Saddress== VISIBLE) { PropertyInfo saddress =new PropertyInfo(); saddress.setName("Saddress");//Define the variable name in the web service method saddress.setValue(saddr);//Define value for fname variable saddress.setType(String.class);//Define the type of the variable request.addProperty(saddress);//Pass properties to the variable } else { PropertyInfo saddress =new PropertyInfo(); saddress.setName("Saddress");//Define the variable name in the web service method saddress.setValue(baddr);//Define value for fname variable saddress.setType(String.class);//Define the type of the variable request.addProperty(saddress);//Pass properties to the variable } 

请在此处查看完整源代码: 完整代码

编辑:

在我的代码中我必须检查复选框意味着Saddress是隐形知道。那时我必须单击按钮意味着插入了baddr值…如果我必须取消选中复选框意味着Saddress值是可见的。那时候我必须插入saddr值。

在这里我必须运行应用程序意味着baddr值是否为Saddered == visible和Saddess ==隐形case.h我可以为这些写条件。

使用

 if(Saddress.getVisibility() == View.VISIBLE){ //.. your code here } 

代替

 if(Saddress== VISIBLE){ //.. your code here } 

因为VISIBLEGONEINVISIBLE是View类的一部分而不是Activity

 EditText editText = (EditText)findViewById(R.id.editText1); editText.getVisibility(); 

这将提供edittext是VISIBLE,INVISIBLE或GONE。

 if(editText.getVisibility() == View.VISIBLE){ //.. your actions are performed here } 

请参阅此 。 你可以找到一些关于VISIBLE , GONE和INVISIBLE的有趣细节