gwt get array button value -


Figures and buttons are shown on each row and cola in my live project.
But my button will not work properly. This is my current code:

Private Button [] B = New Button [] {New Button ("A"), ..., New Button ("J"}}; Private int z = 0; ... Public Zero UpdateTabelGallery (JsArray str) {for (int i = 0; i str.length (); i ++) {b [i] .setText (str.gettitle ()); UpdateTabelGallery (str.get (i)); }} Public Zero UpdateTabelGallery (GalleryData str) {Image img = new image (); Img.setUrl (str.getthumburl ()); HTML hedges = new HTML ("a href =" + str.geturl () + ">" + img + "/ a>" + b [z]); TabelGaleri.setWidget (y, x, hedgehog); // is the right place here? B. [Jade] .addClickHandler {@ Override Public Wide OnClick Click (Event Event) {Window.lert ("I clicked the button to show the text" + B [Z] .gettext ()); }); Z ++; }



I'm still confused where I should have my button handler. Clickhandler with this current code does not work inside a looping. And if I keep it out of the loop which does not work because I need to know which button was clicked, I have to get my index button. But how? Is there any alternative to the array button?

Thanks

The problem is that you reference 'z' in your click handler Take, but the value of z changes, so when your click handler is actually called the value of z is incorrect.

You need a local last variable in UpdateTabelGallery, which allow you to allocate the z of the current value, better than it to be captured by the handler you create, completely Get rid of z and pass i to UpdateTableGallery:

  Public Zune Update TableGallery (GalleryData str, final int i) {Image img = new Image (); Img.setUrl (str.getthumburl ()); HTML Hedges = New HTML ("ARR =" + Straw. TetlL (+ ">" + IMG + "/ A>" + B [ii]); TabelGaleri.setWidget (y, X, hedgehog); // here is the right place? B [i] .addClickHandler (new clickhandler) {@ override public wide onclick click (click event event) {window.lert ("I do not want to show the clicked button text" + B [i] .gettext ());}};}  

But what do you expect:

  html himage = new html (" A href = "+ str.geturl () +" & gt; "+ IMG +" / A & gt; "+ B [i]);  < / Pre> 

To do? In addition to the wrong HTML syntax, I do not think the ypur button has to be added to the string.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -