Configuración de la duración de los mensajes de Crouton en Android

I have started using Crouton messages instead of toast messages because I could configure the time duration. Is there any way I can keep displaying the crouton message until a particular event rather than specifying the time in definite units?

preguntado el 27 de noviembre de 13 a las 05:11

2 Respuestas

You can set the Crouton's duration to INFINITE desde dentro del Configuration. Luego agregue un OnClickListener to it in which you call Crouton.hide(...) Me gusta esto:

final Crouton crouton = Crouton.makeText(new Activity(), "foo", Style.ALERT)
    .setConfiguration(new Configuration.Builder().setDuration(Configuration.DURATION_INFINITE).build());

crouton.setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View v) {
    Crouton.hide(crouton);
  }
});

crouton.show();

respondido 27 nov., 13:09

Thank you for your response, but can I call Crouton.hide(crouton) without the on-click listener? I mean to say, can I call just the hide function in an if-branch? - almarayder

One more question, do the crouton variables have to be final? Or can we declare in some way using normal declarations. Because, currently, the show and hide methods give error if I try with non-final crouton variables. - almarayder

To your first question. You can hide the Crouton any way you want. The second question: Yes, it has to be final, if you're trying to access it from an inner class. - Ben Weiss

After declaring the croutons in the way you have in the MainActivity class, I am calling an AsyncTask from which I call the show and hide functions from runOnUiThread in doInbackground() function. I keep getting null pointer exception related to croutons. Please tell me how to rectify this? - almarayder

This is a different question. Please ask it and include the stack trace there. - Ben Weiss

Instead of using the Crouton library, you can simply add a view y establecer un onClickListener to it. When the user click on it, the view se elimina de la Layout.

respondido 27 nov., 13:06

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.