Android Custom Event Listener not working

Hi Guys,

I thought I would post here first. I’m writing a custom text manipulation class that is drawn on a SurfaceView that does different things. One of the things that it does is move text from one point to another. But, I need to know when it’s done. In comes the Custom Event Listener. This is what I’ve done so far:

In the TextObject class I have:


		    public interface OnMoveDoneListener {
		        public abstract void onMoveDoneEvent();
		    }

and


		    // Allows the user to set a Listener and react to the event
		    public void setOnMoveDoneListener(OnMoveDoneListener onMoveDoneListener2) {
		        onMoveDoneListener = onMoveDoneListener2;
		    }


			/**
			 * Method which updates the droid's internal state every tick
			 */
		    private void onMoveDone() {
		    	if (onMoveDoneListener != null) {
		    		onMoveDoneListener.onMoveDoneEvent();
		    	}
		    }


					if (x_done && y_done) {
						moving = false;
						onMoveDone();
					}


In the activity I have:



	            TextT2.setOnMoveDoneListener(new OnMoveDoneListener(){
	                @Override
	                public void onMoveDoneEvent() {
	                    // Handle the event here
	                    if(true){
	                        TextT2.setText("done.");
	                    } else {
	                        TextT2.setText("Nope.");
	                    }
	                }
	            });	 


This is the error I have:

Maybe there’s something really obvious that I’m missing after having stared at it too long. This is my first time setting up a custom listener. I had to rewrite how my app works because I use alphanimations and after a recent android update (or something) the alphanimation causes the text to disappear, but no matter what I do, the text I’m using will NOT reappear. - especially on Samsung phones. I figured it was time to rewrite it so that I can do more with it.

In case you’re wondering the app is Bible Book Order! https://play.google.com/store/apps/details?id=com.biblebookordergame.biblebookorder&feature=search_result#?t=W251bGwsMSwxLDEsImNvbS5iaWJsZWJvb2tvcmRlcmdhbWUuYmlibGVib29rb3JkZXIiXQ

OR

www.biblebookordergame.com

Anybody have any insights?

Thanks,

Rick

Ok, I forgot to mention that my java skills are very rusty. I’m trying to get them to be good again. :slight_smile:

Here was the problem:


	            TextT2.setOnMoveDoneListener( new TextObject.OnMoveDoneListener () {
	            	public void onMoveDoneEvent() {
	            		TextT2.setText("DONE!!!!....");
	            	}
	    
	            });	


when I was creating the new OnMoveDoneListener interface,
I didn’t put the object reference to it. In the 1.5 million examples I saw, it was just the interface that was referred to and not the class that it was contained in (which is TextObject). Maybe interfaces are supposed to be outside classes? and contained in their own file?

If anybody has some wisdom on this, I’d be happy to hear.

The problem is learning java and then not using it for a while and then using it again.

I need to relearn some of the core concepts of java and get them burned into my brain!

Have a good day,

Rick

Hi,

Just add the import:

import TextObject.OnMoveDoneListener;

or:

import TextObject.*;

That’s probably what all the examples you saw were doing.