问题
I have checked my edittext is visible or invisible in android.
Now i have to check the condition is.,
- If my edittext is visible means how can i insert the data.
- If my edittext is gone means how can i insert on another data.
This is my code for if i have to check the checkbox means the edittext is invisible otherwise the edittext is visible .:
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.
Here below error is showing: VISIBLE cannot be resolved to a variable.
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.
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.
回答1:
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
回答2:
EditText editText = (EditText)findViewById(R.id.editText1);
editText.getVisibility();
this will provide the edittext is VISIBLE, INVISIBLE, or GONE.
if(editText.getVisibility() == View.VISIBLE){
//.. your actions are performed here
}
Refer This. You can find some interesting details about VISIBLE ,GONE and INVISIBLE
来源:https://stackoverflow.com/questions/14555787/edittext-visible-means-how-can-i-check-the-if-condition-in-android