设置EditText可见性

时间:2015-06-11 20:31:43

标签: java android android-edittext visibility

我在XML中设置了EditText四个invisible,当点击button时,我希望它们成对显示。例如,点击button后,我希望et1et2可见,然后再次点击按钮eet1eet2时可见。当所有这些都可见时,我希望TextView可见。

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 个答案:

答案 0 :(得分:0)

设置一个变量,用于存储单击按钮的次数:

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

然后在onClick中增加计数器并区分案例:

public void onClick() {
    switch(counter):
        case 0:
           et1.setVisibility(View.VISIBLE);
           ...
           break;
        case 1:
           ...
           break;
        case ...
    }
    counter++;
}

答案 1 :(得分:0)

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

}