Search code examples
androidcrouton

Crouton with custom view: onClickListener not called


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?


Solution

  • 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.