Reputation: 3050
I am trying to Hide/Show a TableLayout on button click but the animation listener is not working here is the code i am trying
Slide_down = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.slide_down);
Slide_up = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.slide_up);
searchArea = (TableLayout) findViewById(R.id.TableLayout1);
SearchButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (check_tableView == 0) {
Slide_up.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
searchArea.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd(Animation animation) {
searchArea.setVisibility(View.GONE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
check_tableView = 1;
} else {
Slide_down.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
searchArea.setVisibility(View.GONE);
}
@Override
public void onAnimationEnd(Animation animation) {
searchArea.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
check_tableView = 0;
}
}
});
Upvotes: 1
Views: 1177
Reputation: 74
You just set animation listener outside of onClickListener. No need of setting each time View is clicked. Also make sure that you are calling searchArea.startAnimation(Slide_up) and searchArea.startAnimation(Slide_down) method. Call start animation method inside onClickListener.
Upvotes: 0
Reputation: 20041
//just start animation
searchArea = (TableLayout) findViewById(R.id.TableLayout1);
SearchButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (check_tableView == 0) {
searchArea.startAnimation(Slide_up);
}
});
Upvotes: 1