EditText 未恢复 DialogFragment 中的状态
我目前有一个 DialogFragment,其中有几个 EditText 小部件作为其视图的一部分。当方向发生变化时,EditText 小部件不会重新填充其中的文本。
我查看了 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"/>
我正在使用 android 兼容性包。
I currently have a DialogFragment that has a couple of EditText widgets as part of it's view. When there is an orientation change happens the EditText widgets are not repopulated by the text that was in them.
I've looked through the saveInstanceState and the text is being persisted though the orientation change.
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;
}
}
an example EditText:
<EditText
android:text=""
android:id="@+id/loginUsername"
android:layout_width="180dip"
android:layout_height="wrap_content"
android:layout_marginRight="5dip"/>
I am using the android compatibility package.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@CommonsWare我注意到AddFeedDialogFragment使用onCreateDialog方法而不是onCreateView方法。也许这就是数据被正确恢复的原因。
@CommonsWare I noticed that the AddFeedDialogFragment uses the onCreateDialog method and not the onCreateView method. Perhaps thats the reason the data is properly restored.