我设法通过在每个 RadioButton 上添加“actionDownChecker”来做到这一点。
private View.OnTouchListener actionDownChecker = new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN){
mTabbar.check(view.getId());
}
return true;
}
};
public void add(int radioButtonResourceId, Class<? extends Fragment> contentClass) {
mContent.put(radioButtonResourceId, new TabInfo(radioButtonResourceId, contentClass));
//hack to check radio button on ACTION_DOWN, not UP!
mTabbar.findViewById(radioButtonResourceId).setOnTouchListener(actionDownChecker);
}
还有另一种更优雅的方法吗?