I've created tab view using the code example on the android web. http://developer.android.com/training/implementing-navigation/lateral.html
I've added this code to call a the setTitle method which would set the title.
mViewPager.addOnPageChangeListener(
new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
FragmentInterface f = (FragmentInterface) mSectionsPagerAdapter
.getItem(position);
f.setTitle();
}
});
In my fragment class, I've define setTitle as
@Override
public void setTitle() {
System.out.println("Title " + cellMain);
if (cellMain != null) {
getActivity().getActionBar()
.setTitle(cellMain.cellData.getIPWithPort());
}
}
and I also have a button which does :
public void connect(View view) {
System.out.println("Connect " + cellMain);
if (cellMain == null) {
cellMain = CellMain.createAndroid(this,
getActivity().getFilesDir().toString());
getActivity().getActionBar()
.setTitle(cellMain.cellData.getIPWithPort());
}
First I click the button which calls connect, It prints out "Connect null" which is expected as it has not been initialized.
Pressing the button again print out "Connect cell.CellMain@....".
Now I change the view by selecting another tab and changing back to the same tab.
setTitle() method prints out "Title null" which is not expected as cellMain is initialized. Pressing of the button still prints out "Connect cell.CellMain@...."
Why does my setTitle method give a null value for my variable?