有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java将EditText更改为TextView

我想把TextView改成EditText,把TextView改成EditText,因此我决定在安卓上使用ViewSwitcher元素,我在安卓 developer website上读到了它

但我仍有一些不明白的地方:

  1. 如何确定当前开关?(例如,只显示EditText,不显示TextView

这是我的代码:

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

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

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

共 (2) 个答案

  1. # 1 楼答案

    用这个

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

    并随时从代码更改EditTextTextView的可见性

    注意:默认情况下TextView不可见

    希望能有所帮助

  2. # 2 楼答案

    你把相当简单的任务复杂化了。把你的EditTextTextView放进FrameLayoutRelativeLayout里,在需要的时候把它们隐藏起来,然后展示另一个