I have 10 Fragment lists. I am able to swipe and update value of current Fragment. At top of each Fragment i have a list of number like page1, page2, page3...page15 so now i am also want to jump in clicked page fragment. so i am using
viewPagerInstance.setCurrentItem(int position)
it works if i jump left of right page of current page. but if i clicked on another page like as i am in page2 and want to go page10. it give me null pointer exception. i got null error in my resources ( button). is onCreateView working correctly? because all resource has already initialized. so it should not be null.
please help expert
my adapter
public class MyPageAdapter extends FragmentStatePagerAdapter {
private List<Fragment> fragments;
public MyPageAdapter(FragmentManager fm, List<Fragment> fragments) {
super(fm);
this.fragments = fragments;
}
@Override
public Fragment getItem(int position) {
return this.fragments.get(position);
}
@Override
public int getCount() {
return this.fragments.size();
}
onCreateView
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mView = inflater.inflate(R.layout.scorecardtabswingfragment,
container, false);
puttsBtnList = new ArrayList<Button>();
puttsBtnList.add((Button) mView.findViewById(R.id.puttsBtn0));
puttsBtnList.add((Button) mView.findViewById(R.id.puttsBtn1));
puttsBtnList.add((Button) mView.findViewById(R.id.puttsBtn2));
puttsBtnList.add((Button) mView.findViewById(R.id.puttsBtn3));
puttsBtnList.add((Button) mView.findViewById(R.id.puttsBtn4));
puttsBtnList.add((Button) mView.findViewById(R.id.puttsBtn5));
puttsBtnList.add((Button) mView.findViewById(R.id.puttsBtn6));
puttsBtnList.add((Button) mView.findViewById(R.id.puttsBtn7));
puttsBtnList.add((Button) mView.findViewById(R.id.puttsBtn8));
puttsBtnList.add((Button) mView.findViewById(R.id.puttsBtn9));
puttsBtnList.add((Button) mView.findViewById(R.id.puttsBtn10));
puttsBtnList.add((Button) mView.findViewById(R.id.puttsBtn11));
puttsBtnList.add((Button) mView.findViewById(R.id.puttsBtn12));
holeTitle = new TextView[18];
holeTitle[0] = (TextView) mView.findViewById(R.id.tv_hole1);
holeTitle[1] = (TextView) mView.findViewById(R.id.tv_hole2);
holeTitle[2] = (TextView) mView.findViewById(R.id.tv_hole3);
holeTitle[3] = (TextView) mView.findViewById(R.id.tv_hole4);
holeTitle[4] = (TextView) mView.findViewById(R.id.tv_hole5);
holeTitle[5] = (TextView) mView.findViewById(R.id.tv_hole6);
holeTitle[6] = (TextView) mView.findViewById(R.id.tv_hole7);
holeTitle[7] = (TextView) mView.findViewById(R.id.tv_hole8);
holeTitle[8] = (TextView) mView.findViewById(R.id.tv_hole9);
holeTitle[9] = (TextView) mView.findViewById(R.id.tv_hole10);
holeTitle[10] = (TextView) mView.findViewById(R.id.tv_hole11);
holeTitle[11] = (TextView) mView.findViewById(R.id.tv_hole12);
holeTitle[12] = (TextView) mView.findViewById(R.id.tv_hole13);
holeTitle[13] = (TextView) mView.findViewById(R.id.tv_hole14);
holeTitle[14] = (TextView) mView.findViewById(R.id.tv_hole15);
holeTitle[15] = (TextView) mView.findViewById(R.id.tv_hole16);
holeTitle[16] = (TextView) mView.findViewById(R.id.tv_hole17);
holeTitle[17] = (TextView) mView.findViewById(R.id.tv_hole18);
for(ImageButton b: firBtnList) {
b.setOnClickListener(this);
}
for(Button b: penaltyBtnList) {
b.setOnClickListener(this);
}
for(Button b : puttsBtnList) {
b.setOnClickListener(this);
}
for(Button b : storksBtnList) {
b.setOnClickListener(this);
}
for(TextView tv : holeTitle) {
tv.setOnClickListener(this);
}
gpsBtn.setOnClickListener(this);
toggleBtnPlayed.setOnClickListener(this);
//TextView tv_hole = (TextView) mView.findViewById(R.id.tv_hole);
//tv_hole.setText("Hole:"+getArguments().getInt("holeNum"));
doneBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View paramView) {
if(APIUtil.isNeedForUpdate)
//update hole Golfer Scorecard.
new UpdateHoleGolferScorecard(APIUtil.holeno_Update, APIUtil.score_Update,
APIUtil.fir_Update, APIUtil.gir_Update, APIUtil.played_Update, APIUtil.putts_Update).execute();
getActivity().finish();
Intent intent = new Intent(getActivity(), ScorecardsActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
});
swingBtn = (Button) mView.findViewById(R.id.swingBtn);
swingBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
return mView;
}
update
i am using setMenuVisibility of visible property. i think it is calling first and after that onActivityCreated(). I putt my all code into onActivityCreated() and working now. resource is initialized. but is it possible call
onActivityCreated first and after that setMenuVisibility. because for some reason i used it.