Ammar
Ammar

Reputation: 1821

TextView visibility change notification

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.

Upvotes: 1

Views: 2208

Answers (3)

Spurdow
Spurdow

Reputation: 2043

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 :)

Upvotes: 2

pradip_android
pradip_android

Reputation: 303

static boolean textviewon=false;
if(textviewon){
textview.setvisibility(View.Visible);
}else
textview.setvisibility(View.Invisible);

put above condition in your code

Upvotes: 0

user3875707
user3875707

Reputation: 1

visibility="gone" 

in your xml fil

Upvotes: 0

Related Questions