具有自定义视图的Crouton:未调用onClickListener(Crouton with custom view: onClickListener not called)

编程入门 行业动态 更新时间:2024-10-24 10:18:24
具有自定义视图的Crouton:未调用onClickListener(Crouton with custom view: onClickListener not called)

我有一个关于烤面包片的问题:

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,它可以工作。 难道我做错了什么?

I have an issue with crouton:

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); } });

If I provide a customView to the make method, the onClickListener is never called. If I use the makeText, it works. Am I doing something wrong?

最满意答案

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

Adding an OnClickListener to a custom view is not yet supported. The easiest way to handle click events within a custom view Crouton is to add the OnClickListener directly to your custom view.

更多推荐

本文发布于:2023-07-30 00:07:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1320837.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   视图   Crouton   onClickListener   view

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!