2017-03-07 10 views
0

レイアウトファイルにEditTextがあります。ユーザーがこのフィールドをクリックすると、それを下の要素タグに置き換えます。どうすればいいのですか ?EditTextをandroid.support.v7.widget.CardViewタグに置き換えます。

から:

<EditText 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:inputType="textPersonName" 
      android:text="Name" 
      android:ems="10" 
      android:layout_alignParentTop="true" 
      android:layout_marginTop="26dp" /> 

へ:

<android.support.v7.widget.CardView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <fragment 
       android:id="@+id/autocomplete_fragment" 
       android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" /> 
    </android.support.v7.widget.CardView> 

答えて

1

両方のビューにidを渡し、表示をGONEに設定してCardViewを非表示にする

<EditText 
     android:id="@+id/edittext"   
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:inputType="textPersonName" 
     android:text="Name" 
     android:ems="10" 
     android:layout_alignParentTop="true" 
     android:layout_marginTop="26dp" /> 

<android.support.v7.widget.CardView 
     android:id="@+id/cardview" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:visibility="gone"> 

     <fragment 
      android:id="@+id/autocomplete_fragment" 
      android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 
     </android.support.v7.widget.CardView> 

ユーザーがクリックすると、Javaクラスでcardviewとedittextの表示を変更します

mEditText.setOnClickListener(new OnClickListener() { 

    @Override 
    public void onClick(View v) { 
     mEditText.setVisibility(View.GONE); 
     mCardView.setVisibility(View.VISIBLE); 
    } 
}); 
0

最も簡単な解決策はのLinearLayoutまたは類似した何かでそれらを埋め込むために、ユーザーのクリックの可視性を変更することです。 EditTextを非表示にし、CardViewを表示します。

0

レイアウトに追加する必要があります。デフォルトでは、CardViewの可視性はGONEに設定されています。

はその後、ユーザーのクリックを扱うクラスで、View.VISIBLE

0

View.GONECardView視界にEditText可視性を設定するのEditTextのOnClickListeneronClick()メソッド内の実装方法edittext.setVisibility(View.INVISIBLE)cardview.setVisibility(View.VISIBLE)

を呼び出すことによって、あなたのEditTextと再表示cardviewを隠します
関連する問題