M
M
Mr Mojito2018-09-12 13:16:48
Java
Mr Mojito, 2018-09-12 13:16:48

How to make the ExtractEditText object visible/invisible using the Switch switch?

Available in the activate switch Switch and ExtractEditText. What code is required to be written so that the ExtractEditText object was not visible in the inactive Switch switch, but appeared when the Switch was on?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Orkhan, 2018-09-12
@replicate

Hello!
1) add view component switch & edittext to activity.
2) add the following structure:

if (switch1.isChecked()) {
editText.setVisibility(View.VISIBLE);
} else {
editText.setVisibility(View.GONE);
//или editText.setVisibility(View.INVISIBLE);
}

There is a difference between Gone and Invisible. In short... They both hide the view component. However, invisible hides, but takes up space.. And Gone hides and does not take up space...

M
Mr. Mojito, 2018-09-12
@replicate

There was not enough event handler on the switcher, the issue is resolved.

switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    //проверяем свитчер если он активен, то окно с датой появляется
                    if (isChecked){
                        DatePlain.setVisibility(View.VISIBLE);
                    } else {
                        DatePlain.setVisibility(View.GONE);

                    }
                }
            });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question