"Menu" button disabled when I override onKeyDown

by kingkung » Mon, 19 May 2008 16:22:21 GMT


Sponsored Links
 I am overriding onKeyDown in my activity, and calling
super.onKeyDown() on all values except for the "Call" button, which I
implement myself.

The other buttons seem to work, but the Menu fails to load when I hit
the Menu button.  What can I do to get around this?

Thanks,

James

        public boolean onKeyDown(int keyCode, KeyEvent event)
        {
                switch (keyCode)
                {
                        case 5:
                                //perform call function
                                break;
                        default:
                                super.onKeyDown(keyCode,event);
                }
                return true;
        }
--~--~---------~--~----~------------~-------~--~----~



"Menu" button disabled when I override onKeyDown

by Romain Guy » Mon, 19 May 2008 16:29:58 GMT


 Hi,

Returning true from onKeyDown() means "I handled the key event, ignore
it." You are telling the system to ignore the key event. Your code
should return false by default and true only in case 5 (note you
should use the constatnts instead of hard coded values because the key
codes might change.)






-- 
Romain Guy
www.curious-creature.org

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


"Menu" button disabled when I override onKeyDown

by kingkung » Mon, 19 May 2008 18:53:10 GMT


 Thanks, that was it.

Somewhat unrelated, but simple, question... how do I get the menu to
look like a list of items instead of the table format that it's
currently using?




--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Potential bug in the implementation of AppWidgets

Hi

We have discovered a potential bug in the implementation of
AppWidgets. Here is a simple reproducer.

Attached is the code for an application containing a TestActivity and
a TestWidget. TestActivity extends MapActivity and TestWidget is a
simple widget provider which updates a TextView every 2 seconds.
Now if the TestActivity is launched with no instance of TestWidget
running, it works just fine. But if the TestActivity is launched after
placing the TestWidget on the home, it results in
ClassNotFoundException. Here is what we get:

I/ActivityManager(  584): Starting activity: Intent
{ action=android.intent.action.MAIN categories=
{android.intent.category.LAUNCHER} flags=0x10200000 comp=
{com.example.test/com.example.test.TestActivity} }
W/dalvikvm( 1441): Unable to resolve superclass of Lcom/example/test/
TestActivity; (15)
W/dalvikvm( 1441): Link of class 'Lcom/example/test/TestActivity;'
failed
D/AndroidRuntime( 1441): Shutting down VM
W/dalvikvm( 1441): threadid=3: thread exiting with uncaught exception
(group=0x4000fe70)
E/AndroidRuntime( 1441): Uncaught handler: thread main exiting due to
uncaught exception
E/AndroidRuntime( 1441): java.lang.RuntimeException: Unable to
instantiate activity ComponentInfo{com.example.test/
com.example.test.TestActivity}: java.lang.ClassNotFoundException:
com.example.test.TestActivity in loader
dalvik.system.pathclassloa...@49a52110
E/AndroidRuntime( 1441):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2194)
E/AndroidRuntime( 1441):     at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2284)
E/AndroidRuntime( 1441):     at android.app.ActivityThread.access$1800
(ActivityThread.java:112)
E/AndroidRuntime( 1441):     at android.app.ActivityThread
$H.handleMessage(ActivityThread.java:1692)
E/AndroidRuntime( 1441):     at android.os.Handler.dispatchMessage
(Handler.java:99)
E/AndroidRuntime( 1441):     at android.os.Looper.loop(Looper.java:
123)
E/AndroidRuntime( 1441):     at android.app.ActivityThread.main
(ActivityThread.java:3948)
E/AndroidRuntime( 1441):     at java.lang.reflect.Method.invokeNative
(Native Method)
E/AndroidRuntime( 1441):     at java.lang.reflect.Method.invoke
(Method.java:521)
E/AndroidRuntime( 1441):     at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:782)
E/AndroidRuntime( 1441):     at com.android.internal.os.ZygoteInit.main
(ZygoteInit.java:540)
E/AndroidRuntime( 1441):     at dalvik.system.NativeStart.main(Native
Method)
E/AndroidRuntime( 1441): Caused by: java.lang.ClassNotFoundException:
com.example.test.TestActivity in loader
dalvik.system.pathclassloa...@49a52110
E/AndroidRuntime( 1441):     at dalvik.system.PathClassLoader.findClass
(PathClassLoader.java:243)
E/AndroidRuntime( 1441):     at java.lang.ClassLoader.loadClass
(ClassLoader.java:573)
E/AndroidRuntime( 1441):     at java.lang.ClassLoader.loadClass
(ClassLoader.java:532)
E/AndroidRuntime( 1441):     at android.app.Instrumentation.newActivity
(Instrumentation.java:1097)
E/AndroidRuntime( 1441):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2186)
E/AndroidRuntime( 1441):     ... 11 more

So it seems we have an inconsistency in the way the class loader works
for the same apk.

WORKS - Launch the application by itself, without invoking the Widget.
DOES NOT WORK - Create a Widget on the Home screen and then launch the
application from the launcher.

The source code for this application (http://www.yousendit.com/
download/TzY3ZGVhZy96NE4zZUE9PQ) has been attached. Hope someone from
the Android team can shed light on this behavior.

BTW, this error is seen on the 1.5r3 SDK. Not sure if this has been
addressed in 1.6 and 2.0 SDKs..

Thanks,
Himanshu.

-- 

2. My appwidget broken Donut when keyboard slide out/in

Hi String,
     I use static var, i will test it.
Hi Jeff,
   Here is my layout file content. it seems will cause confliction
with others:
Thanks for your kindly help.

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
        android:layout_width="72dp" android:layout_height="72dp"
        android:background="@drawable/bg" android:orientation="vertical"
        android:paddingTop="3dp"
        xmlns:android="http://schemas.android.com/apk/res/android">

        <TextView android:text="TextView01"
                android:layout_width="wrap_content" android:textStyle="bold"
                android:layout_height="14sp" android:id="@+id/TVWeeks"
                android:textSize="12sp"
                android:paddingLeft="8dp"
                android:textColor="#000000">
        </TextView>



        <ImageView android:id="@+id/ImageView01"
                android:layout_width="65sp"
                android:src="@drawable/line"
                android:paddingLeft="5dp"
                android:layout_height="2sp">
        </ImageView>
        <TextView android:text="TextView01"
        android:paddingLeft="8dp"
        android:textSize="12sp"
                android:layout_width="wrap_content" android:textColor="#000000"
                android:layout_height="14sp" android:id="@+id/TVHeight">
        </TextView>



        <TextView android:text="TextView01"
        android:textSize="12sp"
        android:paddingLeft="8dp"
                android:layout_width="wrap_content" android:textColor="#000000"
                android:layout_height="16sp" android:id="@+id/TVWeight">
        </TextView>

<ImageView android:id="@+id/ImageView02"
                android:layout_width="65sp"
                android:src="@drawable/line"
                android:paddingLeft="5dp"
                android:layout_height="2sp">
        </ImageView>
        <TextView android:text="TextView01" android:textColor="#000000"
        android:textSize="12sp"

        android:paddingLeft="8dp"
                android:layout_width="wrap_content"
                android:layout_height="16sp"
                android:id="@+id/TVMomWeiAdded">
        </TextView>




</LinearLayout>









-- 

3. MapView on 1.6 very strange behaviour

4. BroadcastReciver in service

5. Application design - using threads

6. Tutorials: creating 9-patch drawables using SDK tools

7. Building opencore 2 outside android