CHarris
CHarris

Reputation: 2793

My Edittext starts invisible, how do I make it editable when visible?

Normally I'd do it in XML or set it from code with

.setEnabled(true);

but I can't get it working in this case. In a nutshell, the EditText is set to invisible, with a CheckBox click it fades into view and should be editable but... it's not. The EditText fades in and fades out as intended but text can't be typed in the box... What to do?

Here's my code :

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.addcontact);

//      initialise the edittexts
        textcategory = (EditText) findViewById(R.id.textCategory);
        textcategory.setVisibility(View.INVISIBLE);

        fadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.fadein);
        fadeOutAnimation = AnimationUtils.loadAnimation(this, R.anim.fadeout);

//      lets be able to manipuate checkbox,
//        make other things visible or not when checked
        checkBox = (CheckBox) findViewById(R.id.checkBox);

        checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

                if (isChecked) {
                    // Now Set your animation
                    textcategory.startAnimation(fadeInAnimation);
                    fadeInAnimation.setFillAfter(true);

                } else {

                    // Now Set your animation
                    textcategory.startAnimation(fadeOutAnimation);

                }

            }
        });

    }

And my XML :

<EditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="5dp"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:hint="Select a Category"
    android:textSize="18sp"
    android:layout_marginBottom="10dp"
    android:id="@+id/textCategory"
    android:background="@drawable/back"
    android:layout_below="@+id/checkBox"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

Upvotes: 1

Views: 1617

Answers (4)

yourEditText.setVisibility(View.VISIBLE);
yourEditText.setFocusable(true);
yourEditText.setClickable(true);

Upvotes: 0

Rajan Kali
Rajan Kali

Reputation: 12953

In your xml add this line

android:alpha="0"

Then remove this line from your activity

textcategory.setVisibility(View.INVISIBLE);

For animating you can directly use ViewPropertyAnimation as in

checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

     @Override
     public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
           if (isChecked) {
                    // Now Set your animation
                   textcategory.animate().alpha(1).setDuration(1000).start();
                } else {

                    // Now Set your animation
                    textcategory.startAnimation(fadeOutAnimation);
                }
            }
        });

Upvotes: 1

earthw0rmjim
earthw0rmjim

Reputation: 19417

If you've hid your EditText with the following:

textcategory.setVisibility(View.INVISIBLE);

Then, instead of setEnabled(true), you should call the following:

textcategory.setVisibility(View.VISIBLE);

To show it again.

setEnabled() should be called only if you've explicitly disabled your View.

Upvotes: 2

Arnav M.
Arnav M.

Reputation: 2609

setVisibility of textView instead of fadeInAnimation.setFillAfter(true); after animation end.

Upvotes: 1

Related Questions