2

我检查了我的edittext在android中是可见还是不可见。

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

  1. 如果我的编辑文本可见意味着我如何插入数据。
  2. 如果我的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 值同时插入了 Saddress==visible 和 Saddess==invisible case。我该如何为这些写条件。

4

2 回答 2

4

采用

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

代替

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

因为VISIBLE, GONEandINVISIBLE是 View 类而不是 Activity 的一部分

于 2013-01-28T05:10:56.627 回答
1
EditText editText = (EditText)findViewById(R.id.editText1);
editText.getVisibility();

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

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

参考这个你可以找到一些关于VISIBLEGONEINVISIBLE的有趣细节

于 2013-01-28T05:16:10.043 回答