3

我对油煎面包块有疑问:

customView = LayoutInflater.from(context).inflate(viewId, null);
if (customView != null) {
    TextView title = (TextView) customView.findViewById(R.id.crouton_title);
    if (title != null) {
        title.setText(titleString);
    }
    TextView message = (TextView) customView.findViewById(R.id.crouton_message);
    if (message != null) {
        message.setText(messageString);
    }
}

final Crouton crouton = Crouton.make((Activity) context, customView);
crouton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Crouton.hide(crouton);
    }
});

如果我向 make 方法提供 customView,则永远不会调用 onClickListener。如果我使用makeText,它可以工作。难道我做错了什么?

4

1 回答 1

3

OnClickListener尚不支持向自定义视图添加一个。在自定义视图 Crouton 中处理点击事件的最简单方法是将其OnClickListener直接添加到自定义视图中。

于 2013-12-02T17:22:18.833 回答