Closed spung closed 5 years ago
I'd be changing the code to add either an interface or an overridable method you could use to inject your own click handling. The View
for the token is pretty misleading - the tokens displayed only use the View
object to create a template for what should be displayed visually.
Can you talk to me a little more about your use-case?
At a high level, working on a feature where a user can tap on a token to launch a detail screen around that token.
I went ahead with an implementation that adds an extra TokenClickStyle
type which allows the user to specify a click listener when they create their TokenCompleteTextView
. Let me know what you think:
https://github.com/splitwise/TokenAutoComplete/pull/353
I'm pretty hesitant to use the onClick for the view
. Right now, it is possible to put your own click implementation in place without any changes - subclass TokenImageSpan
and override the onClick
in your subclass, then override the buildSpanForObject
method:
@Override
protected TokenImageSpan buildSpanForObject(T obj) {
if (obj == null) {
return null;
}
View tokenView = getViewForObject(obj);
return new ClickableTokenImageSpan(tokenView, obj, (int) maxTextWidth());
}
Mostly I'm concerned about adding the PR you put together because I do not use a reasonable View
hierarchy in the project and I deal with a lot of people being confused that their view methods do not get called when they expect them to. I think adding more behavior tied directly to the view will only make this happen more frequently.
@spung I'm still looking over this kind of change and I'm curious if you ever got your custom click behavior working. From looking over the code, I can't see how you would be locating the token in order to put the detail screen. Did you ever solve this part of the problem?
https://github.com/splitwise/TokenAutoComplete/pull/369 solves the selecting listener and double selecting listener as well.
This maintains the decoupledness of TokenCompleteTextView
What did you have in mind for adding custom click handling? I'd like to launch a new activity when a user taps on a token. I was hoping it'd be as easy as adding a click listener for the view inflated in
getViewForObject()