Setting EditText visibility

109 Views Asked by At

I have four EditText that I set to invisible in the XML and when the button is clicked, I want them to be visible in pairs. For example, when the button is clicked, I want et1 and et2 to be visible, then when the button is clicked again eet1 and eet2 to be visible. And when all of them are visible, i want the TextView to be visible .

public class app extends ActionBarActivity {
EditText et1;
EditText et2;
EditText eet1;
EditText eet2;
TextView sum;
Button button;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_app);
    et1 = (EditText)findViewById(R.id.et1);
    et2 = (EditText)findViewById(R.id.et2);
    eet1 = (EditText)findViewById(R.id.eet1);
    eet2 = (EditText)findViewById(R.id.eet2);
    sum = (TextView)findViewById(R.id.sum);
    button = (Button)findViewById(R.id.button);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onClick();
        }
    });
}

public void onClick() {

        et1.setVisibility(View.VISIBLE);
        eT1.setVisibility(View.VISIBLE);

        eet1.setVisibility(View.VISIBLE);
        eet2.setVisibility(View.VISIBLE);

    }
}
2

There are 2 best solutions below

0
On BEST ANSWER

Set up a variable where you store how many times you clicked the button:

public class app extends ActionBarActivity {
    int counter;
    ...

Then in onClick you increment counter and distinguish cases:

public void onClick() {
    switch(counter):
        case 0:
           et1.setVisibility(View.VISIBLE);
           ...
           break;
        case 1:
           ...
           break;
        case ...
    }
    counter++;
}
0
On
public void onClick() {
    if (if (et1.getVisibility() == View.INVISIBLE &&
            et2.getVisibility() == View.INVISIBLE)) {
            et1.setVisibility(View.VISIBLE);
            eT1.setVisibility(View.VISIBLE);
    } else if() ///... you Get the idea

}