简体   繁体   English

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

[英]edittext visible means how can i check the if condition in android

I have checked my edittext is visible or invisible in android. 我检查了我的edittext在android中可见还是不可见。

Now i have to check the condition is., 现在我要检查条件是。,

  1. If my edittext is visible means how can i insert the data. 如果我的edittext可见,则意味着我该如何插入数据。
  2. If my edittext is gone means how can i insert on another data. 如果我的edittext不见了,那我该如何插入其他数据。

This is my code for if i have to check the checkbox means the edittext is invisible otherwise the edittext is visible .: 这是我的代码,如果我必须选中此复选框,则表示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!!"); 
            }
      }

The below code is ., if my edittext is visible means insert the saddr value.otherwise insert the baddr value.how can i check the condition. 下面的代码是。,如果我的edittext是可见的意味着插入saddr值。否则插入baddr值。我该如何检查条件。

Here below error is showing: VISIBLE cannot be resolved to a variable. 下面的错误显示: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
    }

please see the full source code here: full code 请在此处查看完整的源代码: 完整代码

EDIT: 编辑:

In my code i have to check the checkbox means the Saddress is invisible know.that time i have to click the button means the baddr value is inserted...If i have to uncheck the checkbox means the Saddress value is visible.that time i have to insert the saddr value. 在我的代码中,我必须选中复选框表示Saddress不可见知道。那时候我必须单击按钮意味着就插入了baddr值...如果我必须取消选中复选框则意味着Saddress值是可见的。必须插入saddr值。

Here i have to run the app means the baddr value is insered both Saddress==visible and Saddess==invisible case.how can i write the condition for these. 在这里我必须运行该应用程序,这意味着将在Saddress == visible和Saddess == invisible case.s中插入baddr值。我该如何为它们写条件。

use 采用

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

instead of 代替

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

because VISIBLE , GONE and INVISIBLE is part of View class instead of Activity 因为VISIBLEGONEINVISIBLE是View类而不是Activity的一部分

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

this will provide the edittext is VISIBLE, INVISIBLE, or GONE. 这将提供edittext是VISIBLE,INVISIBLE或GONE。

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

Refer This . 请参阅 You can find some interesting details about VISIBLE , GONE and INVISIBLE 您可以找到有关VISIBLEGONEINVISIBLE的一些有趣的详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM