Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
391 views
in Technique[技术] by (71.8m points)

android - Remove an onclick listener

I have an object where the text cycles and displays status messages. When the messages change, I want the click event of the object to change to take you to the activity that the message is relating to.

So, I have a TextView mTitleView and I'm assigning the event like this.

public void setOnTitleClickListener(OnClickListener listener) {
    mTitleView.setOnClickListener(listener);
}

How do I remove that click event? There are some status messages that do not have an actionable area so I'd like to turn off the click event. I'd also like to be able to cycle through these click events and dispose of them properly, but I'm unsure of the best practice.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

mTitleView.setOnClickListener(null) should do the trick.

A better design might be to do a check of the status in the OnClickListener and then determine whether or not the click should do something vs adding and clearing click listeners.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...