问题
I need to detect when a TextView
is made visible and when its made invisible. Is there any way to do this in Android? I've to make some processing when a TextView
in my application changes visibility. Actually, it's visibility is being updated at a number of places and I'm looking to avoid calls at all of these places.
回答1:
I don't know if this will answer your question, but if you want to listen to textview visibility changes, I suggest customizing TextView and implement your own listener for it.
public class TextViewExtension extends TextView {
protected OnVisibilityChange mChangeListener = null;
public interface OnVisibilityChange {
void onChange(TextViewExtension mTextView, int mPrevVisibility, int mNewVisibility);
}
public TextViewExtension(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
/* (non-Javadoc)
* @see android.view.View#setVisibility(int)
*/
@Override
public void setVisibility(int visibility) {
// TODO Auto-generated method stub
super.setVisibility(visibility);
if (mChangeListener != null) {
mChangeListener.onChange(this, getVisibility(), visibility);
}
}
public void setOnVisibilityChange(OnVisibilityChange mChangeListener) {
this.mChangeListener = mChangeListener;
}
}
Here are examples for further implementation if you are curious
Hope it helps :)
回答2:
visibility="gone"
in your xml fil
回答3:
static boolean textviewon=false;
if(textviewon){
textview.setvisibility(View.Visible);
}else
textview.setvisibility(View.Invisible);
put above condition in your code
来源:https://stackoverflow.com/questions/25153665/textview-visibility-change-notification