简体   繁体   中英

change EditText to TextView

I want to change the TextView to EditText and the TextView to EditText , therefore I decided to use the ViewSwitcher element on android, I read about it on the android developer website .

However I still have some point that I don't understand:

  1. How can I determine the current switch? (for example, to show only the EditText , and to invisible the TextView )

Here is my code:

 <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>

You are complicating quite simple task. Put your EditText and TextView into FrameLayout or RelativeLayout and just do setVisibility() on them hidding one and showing another when needed.

Use this

<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>

And change visibility of EditText or TextView from code, whenever you want.

Note: for default TextView invisible.

Hope it's help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM