我只有一个最简单的应用程序:
MainActivity.java
package com.example.simplestedittext;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main.xml中
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hello_world" >
</EditText>
</LinearLayout>
每当我旋转屏幕时,我都会在Eclipse中收到此消息:
03-28 09:54:46.624:I / TextView(2778):[android.widget.EditText@405320b0不是CheckBox的实例] === ss.text是
如果我在EditText框中输入了“aaa”,则消息将为:
03-28 09:54:53.593:I / TextView(2778):[android.widget.EditText@40541820不是CheckBox的实例] === ss.text是aaa
该消息是什么意思?我的应用程序有问题吗?
而且,你有这些消息吗?
嗯,刚刚注意到,它不仅会在屏幕旋转时发生,也会在切换回此应用时发生。(不,抱歉,不再)
我确信该消息是从super.onRestoreInstanceState();
MainActivity.java
package com.example.simplestedittext;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
System.out.println("before");
super.onRestoreInstanceState(savedInstanceState);
System.out.println("after");
}
}
并输出消息:
03-28 10:33:36.515: I/System.out(4147): before
03-28 10:33:36.515: I/TextView(4147): [android.widget.EditText@4053a138 is not instanceof CheckBox] === ss.text is
03-28 10:33:36.523: I/System.out(4147): after
03-28 10:33:44.328: I/System.out(4147): before
03-28 10:33:44.328: I/TextView(4147): [android.widget.EditText@40549128 is not instanceof CheckBox] === ss.text is aaa
03-28 10:33:44.328: I/System.out(4147): after
希望它可以帮助你帮助我: - )
请注意:没什么会崩溃。我对这个“信息”级日志消息感到好奇(并且不高兴): - /
的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testorientation"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="4"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.testorientation.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
答案 0 :(得分:0)
试试这个
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hello_world" />
答案 1 :(得分:0)
Remove
super.onRestoreInstanceState(savedInstanceState);
from onrestoreinstancestate(); and run again