我是android开发的新手,我想从OnClickListener调用flipCard(),但我不能, 如何调用此方法?我不想(实际上我不能)将flipCard的修饰符更改为静态
这是我的代码:
public class Frags extends Fragment {
private boolean mShowingBack = false;
CardFrontFragment fr = new CardFrontFragment();
CardBackFragment bk = new CardBackFragment();
static View view;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (!mShowingBack) {
return fr.onCreateView(inflater, container, savedInstanceState);
} else {
return bk.onCreateView(inflater, container, savedInstanceState);
}
}
public static class CardFrontFragment extends Fragment {
public CardFrontFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_card_front, container, false);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
/* how to call flipCard() from here? */
}
});
return view;
}
}
public static class CardBackFragment extends Fragment {
public CardBackFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_card_back, container, false);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
}
});
return view;
}
}
public void flipCard() {
if (mShowingBack) {
getChildFragmentManager().popBackStack();
mShowingBack = !true;
return;
}
mShowingBack = true;
getChildFragmentManager()
.beginTransaction()
.setCustomAnimations(
R.animator.card_flip_right_in, R.animator.card_flip_right_out,
R.animator.card_flip_right_in, R.animator.card_flip_right_out)
.replace(R.id.container, this.bk)
.addToBackStack(null)
.commit();
}
}