我已经检查过我的edittext在android中是可见的还是不可见的。
现在我必须检查条件是。,
这是我的代码,如果我必须选中复选框意味着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
}
请在此处查看完整的源代码:full code
修改
在我的代码中我必须选中复选框意味着Saddress是隐形知道的。我必须单击按钮意味着插入了baddr值...如果我必须取消选中该复选框意味着Saddress值可见。那个时候我必须插入saddr值。
这里我必须运行应用程序意味着baddr值是否为Saddered == visible和Saddess ==隐形case.h我可以为这些写入条件。
答案 0 :(得分:3)
使用
if(Saddress.getVisibility() == View.VISIBLE){
//.. your code here
}
而不是
if(Saddress== VISIBLE){
//.. your code here
}
因为VISIBLE
,GONE
和INVISIBLE
是View类的一部分,而不是Activity
答案 1 :(得分:1)