I am using Crouton library to display warning messages to user. In this scenario, I want to display in a particular preference screen. I have written following code in my PreferenceActivity
However, the Crouton is only displayed in the first Preference screen and not on the child preference screen where the Crouton is actually triggered. Any ideas to resolve this issue ?
findPreference(key.key).setOnPreferenceChangeListener(new OnPreferenceChangeListener()
{
@Override
public boolean onPreferenceChange(Preference preference, Object newValue)
{
int count = 0;
for (ANALYTICS_KEYS key : ANALYTICS_KEYS.values())
{
if (appPreferences.getAnalyticProperty(key))
{
count++;
}
}
Crouton crouton = null;
if (count > 5 && count < 7)
{
Style.Builder style = new Builder(Style.INFO).setConfiguration(new Configuration.Builder().setDuration(Configuration.DURATION_INFINITE).build());
crouton = Crouton.makeText(DashAnalyticsPreferenceActivity.this, "More than 5 attributes might not be visible", style.build());
}
else if (count > 7)
{
crouton = Crouton.makeText(DashAnalyticsPreferenceActivity.this, "More than 7 attributes are not allowed. Only first 7 will be considered", Style.ALERT);
}
else
Crouton.cancelAllCroutons();
if (crouton != null)
{
crouton.show();
crouton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
//Crouton.hide(crouton);
}
});
}
return true;
}
The
Crouton
gets attached to the Activites view. Thus it will only be displayed in theActivity
that has been passed to create it.If you want to display a
Crouton
in an otherActivity
you'll have to pass the correspondingActivity
to it.