1.
EditText not re-drawing correctly when the on-screen keyboard is activated.
For a simple app such as:
Bug.java:
package com.matthew1471.bugtest;
import android.app.Activity;
import android.os.Bundle;
public class bug extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
Main.xml:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<EditText android:id="@+id/example" android:layout_width="200.0dip" android:layout_height="wrap_content"/>
<EditText android:layout_width="200.0dip" android:layout_height="wrap_content"/>
<EditText android:layout_width="200.0dip" android:layout_height="wrap_content"/>
<EditText android:layout_width="200.0dip" android:layout_height="wrap_content"/>
<EditText android:layout_width="200.0dip" android:layout_height="wrap_content"/>
<EditText android:layout_width="200.0dip" android:layout_height="wrap_content"/>
<EditText android:layout_width="200.0dip" android:layout_height="wrap_content" />
</LinearLayout>
Manifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.matthew1471.bugtest"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="BugTest">
<activity android:name=".bug"
android:label="BugTest">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
While this shows in the console:
[2011-02-22 01:25:02 - BugTest] WARNING: Application does not specify an API level requirement!
[2011-02-22 01:25:02 - BugTest] Device API version is 8 (Android 2.2.1)
[2011-02-22 01:25:02 - BugTest] Uploading BugTest.apk onto device 'HT<<REMOVED>>'
[2011-02-22 01:25:02 - BugTest] Installing BugTest.apk...
The 5th EditText and onwards when selected and text is entered do not redraw to include the text until the on screen keyboard is closed. For some reason specifying :
<uses-sdk android:minSdkVersion="4"></uses-sdk>
Just before the <application.. tag fixes it. In my application I specified minSdkVersion 8, though anything 4 (Android 1.6,
http://developer.android.com/guide/appendix/api-levels.html) and above fixes the redraw issue. By default the Android system defaults to 1 if not specified (
http://developer.android.com/guide/topics/manifest/uses-sdk-element.html). There must have been something released in Android 1.6 that causes the screen to properly redraw when the on-screen keyboard is activated. The full API change list is documented on the developer site (
http://developer.android.com/sdk/api_diff/4/changes.html)
2.
SetText to an integer causes a misleading force close.
Adding
EditText text = ((EditText)(this.findViewById(R.id.example)));
text.setText(text.getHeight());
to the main part of the above program results in a non-descriptive force close.
02-22 01:48:02.107: WARN/dalvikvm(6248): threadid=1: thread exiting with uncaught exception (group=0x40028a00)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): FATAL EXCEPTION: main
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.matthew1471.bugtest/com.matthew1471.bugtest.bug}: android.content.res.Resources$NotFoundException: String resource ID #0x0
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2781)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2797)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at android.app.ActivityThread.access$2300(ActivityThread.java:135)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2132)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at android.os.Handler.dispatchMessage(Handler.java:99)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at android.os.Looper.loop(Looper.java:143)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at android.app.ActivityThread.main(ActivityThread.java:4914)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at java.lang.reflect.Method.invokeNative(Native Method)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at java.lang.reflect.Method.invoke(Method.java:521)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at dalvik.system.NativeStart.main(Native Method)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at android.content.res.Resources.getText(Resources.java:201)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at android.widget.TextView.setText(TextView.java:2828)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at com.matthew1471.bugtest.bug.onCreate(bug.java:15)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1065)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2745)
02-22 01:48:02.117: ERROR/AndroidRuntime(6248): ... 11 more
02-22 01:48:02.127: WARN/ActivityManager(102): Force finishing activity com.matthew1471.bugtest/.bug
Which would make you think it cannot find the example EditText in the layout. However changing the second line to :
text.setText("" + text.getHeight());
resolves all the issues. setText is not happy casting an int to a string because usually when an int is specified it corresponds to a program's string in the strings.xml file unless tricked into dealing with strings. There is also seemingly no .tostring() method on an int but there is one for Integer.toString();
The same force close exists with:
int five = 5;
text.setText(five);