2016-06-14 9 views
1

通常、私はXMLでそれを行うか、My Edittextが非表示になります。表示されたときに編集可能にするにはどうすればよいですか?

.setEnabled(true); 

でコードから、それを設定するが、私はそれがこのケースで働いて得ることができないと思います。簡単に言えば、EditTextは不可視に設定されており、CheckBoxクリックすると表示が消えて編集可能になるはずですが...そうではありません。 EditTextは意図したとおりにフェードインしてフェードアウトしますが、テキストをボックスに入力することはできません。どうしたらいいですか?

@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); 

       } 

      } 
     }); 

    } 

そして、私の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" /> 
+1

としてViewPropertyAnimationを使用することができますアニメーションのためにあなたの活動

textcategory.setVisibility(View.INVISIBLE); 

からこの行を削除し、この行を追加します。あなたはedittextのコードを書いています表示、非表示、編集可能ですか? – Vickyexpert

+0

View.INVISIBLEの代わりにView.GONEを使用してください。 – Array

+0

@Array。私はそれが問題を解決するとは思わない。 View.GONEは、私のEditTextがまったく存在しないのと同じように、他のビューがそのスペースを占めるようにします。 View.INVISIBLEはプレースホルダに似ていますが、ビューを見ることはできませんが、XMLまたはJavaコードで設定された領域を占有します。 – CHarris

答えて

2

は:

textcategory.setVisibility(View.INVISIBLE); 

その後、代わりにsetEnabled(true)のは、次のように呼び出す必要があります:

textcategory.setVisibility(View.VISIBLE); 

再びそれを表示します。

setEnabled()は、Viewを明示的に無効にした場合にのみ呼び出される必要があります。あなたのXMLで

+0

Aha。したがって、フェードインで「可視」になっても、可視性をVISIBLEに設定する必要があります。 – CHarris

1

のTextViewのsetVisibility代わりにfadeInAnimation.setFillAfter(true);

は、ここに私のコードです。あなたは、次のとあなたのEditTextを隠した場合

1

android:alpha="0" 

は、その後、あなたが直接で

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); 
       } 
      } 
     }); 
+0

それをxmlに追加して、設定可能性を削除しても、それを動作させることができませんでした。あなたのViewPropertyAnimationは面白そうです。 – CHarris

0
yourEditText.setVisibility(View.VISIBLE); 
yourEditText.setFocusable(true); 
yourEditText.setClickable(true); 
関連する問題