KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I've been searching for a KISS example of how to do this, and while they all seem (and I've gone through them ALL!) simple enough, I still cannot get my head around the concept. I'm referring to custom listeners (ones that do not extend anything)... In particular, creating a listener for a boolean variable so that I can set off some methods when its value changes. this is an example of an example I've tried: android how to make listener to a custom variable? If someone has the time to explain a custom listener and how it works in plain English, that would be much appreciated. I'm hoping that once I understand exactly how the listener is notified of a change, then I'll be able to create my own and understand how the damn thing works. This is giving me a headache... Thanks in advance Here is where I'm at at the moment: public class ChangeListener { boolean boo = false; public ChangeListener(boolean b){ boo = b; } private listener l = null; public interface listener{ public void onChange(boolean b); } public void setChangeListener(listener mListener){ l = mListener; } public void somethingChanged(){ if(l != null){ l.onChange(boo); } } } This is a snapshot of my main activity: public class Main extends Activity implements ChangeListener.listener{ private ChangeListener listener; private boolean boo = false; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); listener = new ChangeListener(boo); listener.setChangeListener(this); listener.somethingChanged(); } @Override public void onChange(boolean b) { // TODO Auto-generated method stub
Tags (comma-separated)
Save Edits
Cancel