2013-04-09 49 views
1

我想改變TextViewEditTextTextViewEditText,所以我決定用ViewSwitcher元素在Android上,我就android developer website讀到它。變化的EditText TextView的到

但是我仍然有一些點,我不明白:

  1. 我怎麼能確定目前的開關? (例如,只顯示EditText,以及無形TextView

這裏是我的代碼:

<ViewSwitcher 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/my_switcher" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" > 

     <TextView 
      android:id="@+id/clickable_text_view" 
      android:clickable="true" 
      android:onClick="TextViewClicked" 
      android:text="@string/some_value" /> 

     <EditText 
      android:id="@+id/hidden_edit_view" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:hint="@string/some_value" > 
     </EditText> 
    </ViewSwitcher> 

回答

3

您都相當簡單的事情複雜化。把你的EditTextTextView分別轉換成FrameLayoutRelativeLayout,然後setVisibility()就可以隱藏一個,並在需要時顯示另一個。

+0

非常感謝!它真的幫助我 – 2013-04-09 13:52:24

0

使用此

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/my_switcher" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

<TextView 
     android:id="@+id/clickable_text_view" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:clickable="true" 
     android:onClick="TextViewClicked" 
     android:text="@string/some_value" 
     android:visibility="gone"/> 

<EditText 
     android:id="@+id/hidden_edit_view" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:hint="@string/some_value" > 
</EditText> 

和變化的EditText或代碼TextView,只要你想的可視性。

注意:默認TextView隱形。

希望它的幫助。