0

How to identify the button clicked?

asked 2009-07-03 08:12:21 +0800

TLHP gravatar image TLHP
111 1 3

updated 2009-07-03 08:23:41 +0800

Hello!
I have a problem:
I have a list of buttons which are added in a dynamic way, so I don't know the number, but each button is added in a div. In fact I create in a dynamic way a div containing a button.
Then I want that a textbox appears by clicking on a button in this button's div.
I think that I need to get the id of the button clicked but I don't know how to do that.
If someone know how to do or have an other idea... I am completely blocked.

Thank you in advance

delete flag offensive retag edit

6 Replies

Sort by ยป oldest newest

answered 2009-07-03 08:28:06 +0800

pfellmann gravatar image pfellmann
42

when you create your button :

Button myButton = new Button("myButtonLabel");a.setId("myButtonId");

now he's got an Id ;)

link publish delete flag offensive edit

answered 2009-07-03 08:35:15 +0800

TLHP gravatar image TLHP
111 1 3

Hello pfellmann,
the problem is not to give an Id to the button but to get it from a fonction onClick.
I have the same method for all buttons but I want to know which button has been clicked in order to display something in this button's div.
Thank you for your answer by the way :-)

link publish delete flag offensive edit

answered 2009-07-03 10:58:43 +0800

pfellmann gravatar image pfellmann
42

Sorry, I didn't understand your question in the first place.
You can try :

Public Class myController extends GenericForwardComposer (){

  private void myButtonCreationMethod (){

    Button myButton = new Button("myButtonLabel");
    myButton.setId("myButtonId");
    myButton.setAttribute("onClick","myOnClickMethod");
    //or maybe mypackage.myController.myOnClickMethod ... I didn't test it
    }

    public void myOnClickMethod(Event e){
// ........
    }
}

you just have to find a way to know what button is pressed, maybe somewhere in e.getXXX ... I don't know, but I think it's in the right way !

Let me know if you find out !
good luck!

link publish delete flag offensive edit

answered 2009-07-03 11:03:38 +0800

TLHP gravatar image TLHP
111 1 3

Yes there is a e.getId, but the problem is that the e is not visible in the onClick method...

link publish delete flag offensive edit

answered 2009-07-03 14:45:57 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2009-07-03 14:46:30 +0800

Hi, why not ??

add an eventListener

   ...
   Button btn = new Button("ZK Guestbook");
   btn.setID("btnId");
   btn.setParent(getMainMenuWindow());
   btn.addEventListener("onClick", new GuestBookListener());
   ...
   }

	public final class GuestBookListener implements EventListener {
		@Override
		public void onEvent(Event event) throws Exception {
                   
                     // get the id of the component 
 			event.getTarget().getId()

                     // do something

		}
	}

regards
Stephan

link publish delete flag offensive edit

answered 2009-07-08 14:58:36 +0800

TLHP gravatar image TLHP
111 1 3

thanks Stephan, will try it right now :x

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-07-03 08:12:21 +0800

Seen: 623 times

Last updated: Jul 08 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More