getOnClickListener() in Android views

后端 未结 5 969
别跟我提以往
别跟我提以往 2020-12-05 23:52

I need a getOnClickListener() for Views in Android. This way I can assign a temporary OnClickListener to my Views. I want to use it like this:

private View.         


        
5条回答
  •  悲哀的现实
    2020-12-06 00:34

    Niet!

    The oldListener in the answers given is in each case being redefined and it's old state or definition is lost regardless of it's name pretending otherwise.

    Following this technique: Get current onClickListener of an Android View object the 'old' listener would be set in the abstract class's onClick method and any temporary listener would use setOnClickListener along with a call to super in order to (re)set the old listener when or as appropriate

    The temp listener setting code need not know what the 'old' listener is however there still needs to be some form of coordination in order for the author of that or those listeners to make them abstract and use the onClick method to set the on click listener, in short, to follow a protocol.

    Exceptionally you might want to bypass the protected or private qualifier of the onclicklistener View member: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.1_r2/android/view/View.java#View.0mOnClickListener and then do a little http://www.jguru.com/faq/view.jsp?EID=321191 which will get you the listener.

    You might even want to write your own getOnClickListener, or any getter for that matter, that uses the instrospection approach, if of course it actually works :)

    :)

提交回复
热议问题