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. bongkar AHA Touch

ada yang sudah punya rom untuk aha touch

saya pengen buang ini gambar2 default2 Esia

F

-- 
===============

2. HH Android Diskon ..(paging grand ponsel)

---------- Pesan terusan ----------
Dari: nano suparno <suparno...@gmail.com>
Tanggal: 1 Februari 2011 10.59
Subjek: HH Android Diskon ..(paging grand ponsel)
Ke: id-android@googlegroups.com


dear teman2 androiders semua.

Kemarin saya dapat sms dari grand ponsel, katanya ada diskon hingga 40%
aneka handheld.
Langsung saya cek di website nya terpampang disitu aneka HH dengan diskon
yang wah.
Cuma saya blm pernah transaksi dengan grand ponsel ini... masih khawatir...
Mungkin teman2 ada yang pernah transaksi...mohon testimoninya...

Ini alamatnya:
http://www.grandponsel.com/index.php?route=product/category&path=47

-- 
===============

3. Game untuk batita

4. Twidroyd Suspended?

5. Bitmap problem - application crashes

6. Google Map Error

7. Android kernel-debugger