gpt4 book ai didi

java - 将导航按钮添加到 AbstractCell

转载 作者:行者123 更新时间:2023-11-28 18:47:51 27 4
gpt4 key购买 nike

我创建了一个 AbstractCell<String>创建 header “欢迎使用您的手机...”,我想在此 AbstractCell 中添加两个按钮: 第一个返回上一页,第二个返回欢迎页面。我曾经创建标题元素一个扩展 AbstractCell<String> 的类使用此代码:

public class HeaderCell extends AbstractCell<String> {

interface Templates extends SafeHtmlTemplates {

String style = "HeaderPanel";

@SafeHtmlTemplates.Template("<div class=\""+style+"\">{0}</div>")
SafeHtml cell(SafeHtml value);
}

private Templates templates = GWT.create(Templates.class);

interface templateWithButton extends SafeHtmlTemplates {

}
@Override
public void render(com.google.gwt.cell.client.Cell.Context context,
String value, SafeHtmlBuilder sb) {
SafeHtml safeValue = SafeHtmlUtils.fromString(value);

SafeHtml rendered = templates.cell(safeValue);

sb.append(rendered);
}

}

请问有什么方法可以添加这两个按钮吗?请注意标题单元格为黑色。PS:要设置如下图所示的标题元素,我使用了这个 CSS:

.HeaderPanel {
-moz-box-shadow: inset -1px -1px 15px 1px #ffffff;
-webkit-box-shadow: inset -1px -1px 15px 1px #ffffff;
box-shadow: inset -1px -1px 15px 1px #ffffff;
background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #242524
), color-stop(1, #242524) );
background: -moz-linear-gradient(center top, #242524 5%, #242524 100%);
background-color: #242524;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
border-radius: 7px;
border: 1px solid #dcdcdc;
color: #ffffff;
font-family: arial;
font-size: 17px;
font-weight: bold;
padding: 8px 36px;
text-decoration: none;
text-shadow: 1px 1px 29px #ffffff;
text-align: center;
}

http://hpics.li/5e81f65

最佳答案

我不确定这是否是最佳实现方式,但它适合我。-- 首先,将其添加到您的构造函数中:

public HeaderCell() {
super("click", "keydown");
}

-- 然后,覆盖 onBrowserEvent:

@Override
public void onBrowserEvent(Context context, Element parent, String value, NativeEvent event, ValueUpdater<String> valueUpdater) {
// Let AbstractCell handle the keydown event.
super.onBrowserEvent(context, parent, value, event, valueUpdater);
// Handle the click event.
if ("click".equals(event.getType())) {
EventTarget eventTarget = event.getEventTarget();
// in here we check whether the cell that was being clicked is an image, not the entire cell
if(eventTarget.toString().contains("img src") && !eventTarget.toString().contains("<div class")){
// do something if it's indeed the image that was clicked
}
}
}

干杯,林

关于java - 将导航按钮添加到 AbstractCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10103998/

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