设备旋转后未设置EditText [英] EditText not set after device rotation

查看:82
本文介绍了设备旋转后未设置EditText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

步骤如下: 1.运行应用程序->确定,将EditText设置为"hello" 2.手动清除文字 3.旋转设备

Steps are as follows: 1. Run app -> OK, EditText set to "hello" 2. Clear text manually 3. Rotate the device

我希望将EditText再次设置为"hello",因为在旋转后会重新创建活动.但是,EditText为空.代码:

What I expect is that EditText is set again to "hello" because activity is recreated after rotation. However, EditText is empty. Code:

public class MainActivity extends AppCompatActivity {

EditText editText;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    editText = (EditText) findViewById(R.id.editText1);
    editText.setText("hello");
}
}

推荐答案

尝试将以下内容添加到xml布局的EditText规范中:

Try to add the following to your EditText specification in xml layout:

android:saveEnabled="false"

这篇关于设备旋转后未设置EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆