我想在最后一个页面中设置visible
一个button
,但是最后一个元素没有调用片段constructor
。(我已经调试过了)
public Fragment getItem(int i) {
Fragment fragment = new DemoObjectFragment();
Bundle args = new Bundle();
args.putParcelable(DemoObjectFragment.ARG_OBJECT, check.getQuestionWithId(i));
if(check.getNQuestions()==i)
args.putBoolean(DemoObjectFragment.FINAL_QUEST,true);
@Override
public int getCount() {
return check.getNQuestions();
}
和DemoObjectFragment:
public static class DemoObjectFragment extends Fragment {
public static final String ARG_OBJECT = "QUESTION";
public static final String FINAL_QUEST = "FINAL_QUEST";
public static final int requestCode_AnswerActivity = 1;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.question_fragment, container, false);
Bundle args = getArguments();
final Question quest = args.getParcelable(ARG_OBJECT);
((TextView) rootView.findViewById(android.R.id.text1)).setText(
quest.getContent());
if(args.getBoolean(FINAL_QUEST)) {
Button finish_test = (Button) rootView.findViewById(R.id.button_finish_test);
finish_test.setVisibility(View.VISIBLE);
}
}
}
谢谢。
发布于 2015-04-27 09:27:52
这是可能的,因为您的FragmentStatePagerAdapter
重用了现有的Fragment
。试试这些,让它工作起来:
getItem()
方法中设置按钮的可见性,而不是在onCreateView()
中。INVISIBLE
--您必须在每次重用Fragment
时决定按钮的可见性。https://stackoverflow.com/questions/29891373
复制相似问题