gpt4 book ai didi

java - 为单元列表中添加的按钮单元添加 clickHandler

转载 作者:行者123 更新时间:2023-12-01 14:10:12 25 4
gpt4 key购买 nike

我创建了一个 cellList :我想在用户单击“发送”按钮时添加点击处理程序

请帮忙。如果用户单击“发送”按钮,FieldUpdater 应该可以工作。

这是代码:

  final String imageHtml =AbstractImagePrototype.create(images.contact()).getHTML();
// first make a list of HasCell type - MyClass is the type of object being displayed in the CellList (could be String for simple labels)
List<HasCell<contactinfo, ?>> hasCells = new ArrayList<HasCell<contactinfo, ?>>();

hasCells.add(new HasCell<contactinfo, String>()
{
public ButtonCell cell = new ButtonCell();

public Cell<String> getCell()
{
return cell;
}

@Override
public String getValue(contactinfo object)
{
return "Send";
}

@Override
public FieldUpdater<contactinfo, String> getFieldUpdater() {
FieldUpdater< contactinfo, String > updater= new FieldUpdater<contactinfo, String>() {

@Override
public void update(int index, contactinfo object, String value) {
Window.alert("You clicked "+object.getName());
}

};
return updater;
}

}

);

// now construct the actual composite cell using the list (hasCells)
Cell<contactinfo> myClassCell = new CompositeCell<contactinfo>(hasCells)
{
@Override
public void render(Context context, contactinfo value, SafeHtmlBuilder sb)
{
sb.appendHtmlConstant("<table><tbody><tr>");
super.render(context, value, sb);
sb.appendHtmlConstant("</tr></tbody></table>");
}
@Override
protected Element getContainerElement(Element parent)
{
// Return the first TR element in the table.
return parent.getFirstChildElement().getFirstChildElement();
}
@Override
protected <X> void render(Context context, contactinfo contactinfo, SafeHtmlBuilder sb, HasCell<contactinfo, X> hasCell)
{

这会将复合单元格内的每个单元格呈现在新的表格单元格中

        // Value can be null, so do a null check..
if (contactinfo == null) {
return;
}

sb.appendHtmlConstant("<table>");

// Add the contact image.
sb.appendHtmlConstant("<tr><td rowspan='3'>");
sb.appendHtmlConstant(imageHtml);
sb.appendHtmlConstant("</td>");

// Add the name and address.
sb.appendHtmlConstant("<td style='font-size:95%;'>");
if(contactinfo.getName()!=null)
sb.appendEscaped(contactinfo.getName());
sb.appendHtmlConstant("</td></tr><tr><td>");
if(contactinfo.getAddress()!=null)
sb.appendEscaped(contactinfo.getRemarks());
sb.appendHtmlConstant("</td>");
Cell<X> cell = hasCell.getCell();
sb.appendHtmlConstant("<td>");
cell.render(context, hasCell.getValue(contactinfo), sb);
sb.appendHtmlConstant("</td></tr></table>");
}
};
// then make the actual cellList, passing the composite cell
cellList =new CellList<contactinfo>(myClassCell,KEY_PROVIDER);
// Add a selection model so we m select cells.
singleselectionModel = new SingleSelectionModel<contactinfo>(
KEY_PROVIDER);


cellList.setSelectionModel(singleselectionModel);
singleselectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {

@Override
public void onSelectionChange(SelectionChangeEvent event) {

}
});

最佳答案

此外,我在代码中没有看到任何处理事件的部分。您读过http://www.gwtproject.org/doc/latest/DevGuideUiCustomCells.html#cell-onBrowserEvent吗?

您是否尝试过 GWT 提供的代码示例 - http://gwt.googleusercontent.com/samples/Showcase/Showcase.html#!CwCellSampler 。浏览“源代码”!!!

如果您还没有阅读过,那么您应该从这里开始@ DevGuideUiCustomCells

关于java - 为单元列表中添加的按钮单元添加 clickHandler,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18572197/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com