I thought you couldn't instantiate interfaces?

by Mark Murphy » Wed, 31 Mar 2010 01:05:30 GMT

Sponsored Links

This code is creating an instance of an anonymous inner class that
implements the interface.

Possible, yes. "Better" is difficult to answer in the abstract.

I tend to make longer anonymous inner classes be private data members:

private View.OnKeyListener onKey=new View.OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (event.getAction() == KeyEvent.ACTION_DOWN)
                        if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
                                return true;
                return false;

then call myEditText.setOnKeyListener(onKey) where needed. But that's
just me.

Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

_Android Programming Tutorials_ Version 2.0 Available!


Other Threads

1. "unknown socket error " Is anyone know this error??


I think the problem was about the url convention, Here is my example:

*  private static final String URL = "

you see full source code of my example from Exam: Web Service Client for
Android SDK 
Note: any result, please let me know too. :)

Chaiyasit T.


2. Question about built-in content providers

I understand that people can rip it apart and do whatever with it so
my main concern is about "official" android releases.

Can someone from Google comment if the support for all built in
content providers is a requirement for being able to run Android
Market or is this part not regulated? I'm asking because when I'm
developing an app that will be published on the Android Market, do I
have to design for all cases where a particular built-in content
provider (or part of it) is not supported?



3. Audio Playback while Recording... ------- attemp playback while recording, cheat it! ----- error

4. Fwd: Device Driver Development for Android

5. BaseAdapter getView() gets called 3x per item

6. Managing background uploads

7. Uninstall not working