페이지

2011년 5월 25일 수요일

FreezesText - EditText

EditText 에서 android:freezesText = "true" 설정하면 화면 모드 전환시 EditText가
현재 상태를 계속 유지 할수있다.
( 현재 커서 위치, 입력된 Text 임시 저장 )

간단한 예제를 살펴보자.

    <EditText android:id="@+id/saved"
        android:layout_width="match_parent" android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/green"
        android:text="@string/initial_text"
        android:freezesText="true">
        <requestFocus /> - 해당 EditText 에 포커스를 주기 위해서 추가함.    </EditText>


public class SaveRestoreState extends Activity
{
    @Override
 protected void onCreate(Bundle savedInstanceState) {
        // Be sure to call the super class.
        super.onCreate(savedInstanceState);
        // See assets/res/any/layout/save_restore_state.xml for this
        // view layout definition, which is being set here as
        // the content of our screen.
        setContentView(R.layout.save_restore_state);
        // Set message to be appropriate for this screen.
        ((TextView)findViewById(R.id.msg)).setText(R.string.save_restore_msg);
    }
    /**
     * Retrieve the text that is currently in the "saved" editor.
     */
    CharSequence getSavedText() {
        return ((EditText)findViewById(R.id.saved)).getText();
    }

    /**
     * Change the text that is currently in the "saved" editor.
     */
    void setSavedText(CharSequence text) {
        ((EditText)findViewById(R.id.saved)).setText(text);
    }
}

댓글 없음:

댓글 쓰기