Reputation: 41
I am using @MrEngineer13's SnackBar implementation and was wondering how to capture 2 separate "ActionClick" events - depending on when the actionclick event occurs, I need to do different things.
The builder looks like this -
new SnackBar.Builder(this)
.withOnClickListener(this)
.withMessage("This library is awesome!") // OR
.withMessageId(messageId)
.withTypeFace(myAwesomeTypeFace)
.withActionMessage("Action") // OR
.withActionMessageId(actionMsgId)
.withTextColorId(textColorId)
.withBackGroundColorId(bgColorId)
.withVisibilityChangeListener(this)
.withStyle(style)
.withDuration(duration)
.show();`
and the onMessageClick takes a "token" parameter -
@Override
public void onMessageClick(Parcelable token) {
}
What I am not able to figure out is, how to pass this "token" when the click happens.
Upvotes: 0
Views: 34
Reputation: 1006539
depending on when the actionclick event occurs, I need to do different things
Handle that in the body of onMessageClick()
:
@Override
public void onMessageClick(Parcelable token) {
if (shouldIDoX()) {
doX();
}
else {
doY();
}
}
(where you supply relevant implementations of shouldIDoX()
, doX()
, and doY()
.
What I am not able to figure out is, how to pass this "token" when the click happens
There is a withToken()
method on the Builder
that you can use to supply the Parcelable
to be passed into onMessageClick()
. That being said, the JavaDocs describe it as "The token used to restore the SnackBar state", which would make me a bit nervous about messing with it.
Upvotes: 1