2011-05-06 69 views
6

我目前有一個DialogFragment有一些EditText小部件作爲其視圖的一部分。當發生方向更改時,EditText小部件不會被其中的文本重新填充。EditText不恢復狀態在DialogFragment

我已經看過了saveInstanceState,並且文本正在通過方向更改持久保存。

DialogFragment:

public final class LoginDialog extends DialogFragment { 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    View v = inflater.inflate(R.layout.login, container, false); 
    return v; 
    } 
} 

一個例子的EditText:

<EditText 
android:text="" 
android:id="@+id/loginUsername" 
android:layout_width="180dip" 
android:layout_height="wrap_content" 
android:layout_marginRight="5dip"/> 

我使用的機器人兼容性包。

+1

FWIW,這是一個(精心製作的)示例項目,其中包含一個不存在此問題的DialogFragment:https://github.com/commonsguy/cw-advandroid/tree/master/Honeycomb/FeedFragments – CommonsWare 2011-05-06 10:13:30

回答

0

@CommonsWare我注意到AddFeedDialogFragment使用onCreateDialog方法,而不是onCreateView方法。也許這就是數據正確恢復的原因。

+0

您應該像你說的那樣膨脹onCreateDialog中的視圖。你是這個問題的作者嗎?如果是這樣,你已經嘗試過了嗎? – quinestor 2012-10-19 16:32:10