Use standard Android Activity template to switch between editing and viewing

Asked

Viewed 82 times

-1

I have a activity which serves to display the User Profile, so it lists information about this user. I want to know how does that standard already adopted by Android in Actionbar stay an icon to edit information and what was TextView, turn EditText, that’s in a activity only or two?

1 answer

4

in case, for you to 'exchange' a textview for edittext you can use a Viewswitcher

Example:

-- LAYOUT

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

-- ACTIVITY

public void TextViewClicked() {
    ViewSwitcher switcher = (ViewSwitcher) findViewById(R.id.my_switcher);
    switcher.showNext(); //or switcher.showPrevious();
    TextView myTV = (TextView) switcher.findViewById(R.id.clickable_text_view);
    myTV.setText("value");
}

however, when it comes to a lot of information I never got to evaluate if this solution impacts on performance.

particularly, in most cases, I directly instate an edittext in 'Enable:false' mode and when it triggers the edit button I enable editing of the edittext 'Enable: true'.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.