Reputation: 713
I need to know when animation ends if user select a RadioButton from a Radiogroup.
My Case: I have a viewPager with questions when user answers at my question then move to the next position (question).
Sample code:
@Override
public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
RadioButton checkedRadioButton = (RadioButton) group.findViewById(checkedId);
viewPagerHelper.goToNext();
Log.e("CardAdapter", "Text :" + checkedRadioButton.getText());
}
thanks
Upvotes: 5
Views: 564
Reputation: 1035
If I understand your case, have you tried something like this ?
Edit : If you add an animation listener ? not works, throw a NullPointer on getAnimation()
RadioGroup myRadioGroup = (RadioGroup) _view.findViewById(R.id.rg);
myRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
switch (checkedId) {
case R.id.rb1 : // do something
break;
case R.id.rb2 : // do something else
break;
}
}
});
myRadioGroup.getAnimation().setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
// crossing fingers
goToNextQuestion();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
Edit2 : SHITTY solution ! DO NOT do this at home please
I'm not proud of it, but it's works with this solution
myRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this, "test", Toast.LENGTH_SHORT).show();
}
}, 250);
}
});
250 milliseconds are purely estimated.
I hope that will help you
Upvotes: 1