Is it possible to determine the originating AutoCompleteTextView from the parameters of the callback onItemClick?
I have the following callback function, which is correctly triggered if I click on an item of the selection-popup-window of the AutoCompleteTextView:
public void onItemClick(AdapterView<?> adaptView, View view, int position,
long id) {
}
I know, that I can implement an own per-textview listener class, but I would like to determine which AutoCompleteTextView initiated the click solely from the parameters of the callback function - is this possible?
I do not have a positive answer to the question (I think it is not possible). But I use a workaround to reach the same goal (find AutoCompleteTextView from within onItemClick):
I defined the following class, which can be used to modify the onItemClick call to provide the AutoCompleteTextView as second parameter (instead of original View param).
public class AutoCompleteTextViewClickListener implements OnItemClickListener {
AutoCompleteTextView mAutoComplete;
OnItemClickListener mOriginalListener;
public AutoCompleteTextViewClickListener(AutoCompleteTextView acTextView,
OnItemClickListener originalListener) {
mAutoComplete = acTextView;
mOriginalListener = originalListener;
}
public void onItemClick(AdapterView<?> adView, View view, int position,
long id) {
mOriginalListener.onItemClick(adView, mAutoComplete, position, id);
}
}
This can be used in the following way:
Instead of
myTextView.setOnItemClickListener(myListener);
you'll have to write:
myTextView.setOnItemClickListener(
new AutoCompleteTextViewClickListener(myTextView, myListener));
Now, whenever onItemClicked is triggered by the TextView, instead of the original view value the reference to the AutoCompleteTextView is available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With