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) {
                                todoItems.add(0, 
myEditText.getText().toString());
                                aa.notifyDataSetChanged();
                                myEditText.setText("");
                                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??

Hi,

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

*  private static final String URL = "
http://www.codemobiles.com/nusoap/samples/authen_ws.php";

you see full source code of my example from Exam: Web Service Client for
Android SDK 
Ver-1.1,1.5,1.6<%20%20private%20static%20final%20String%20URL%20=%20%22http://www.codemobiles.com/nusoap/samples/authen_ws.php%22;>
*
Note: any result, please let me know too. :)

Chaiyasit T.
www.codemobiles.com*
*








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

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?


Tauno






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

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