Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialLeon Mathis
23,404 PointsNAVIGATION_MODE_TABS are deprecated on MainActivity and errors STILL on SectionPagerAdapter.java on returnFragment
After doing the video twice and following all other forum questions. It seems I can't fix this bug.
Issue 1 After MainActivity extends FragmentActivity it brings up an error on final ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
getSupportActionBar is highleted red and the rest of the code is crossed out. Also changed "getSupportActionBar" to "getActionBar". Still error.
Issue 2 After following all other questions and links, 'return new InboxFragment();' and Frinds brings up an error. Says android.support.v4.app.Fragment; is required but it imported on all tabs.
What am I doing wrong?
p.s. cleaned and rebuilt project
Leon Mathis
23,404 Pointsimport java.util.Locale;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.content.Context;
import java.util.Locale;
/**
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
* one of the sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentPagerAdapter {
protected Context mContext;
public SectionsPagerAdapter(Context context, FragmentManager fm) {
super(fm);
mContext = context;
}
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class
// below).
switch(position) {
case 0:
return new InboxFragment();
case 1:
return new FriendsFragment();
}
return null;
}
@Override
public int getCount() {
// Show 2 total pages.
return 2;
}
@Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (position) {
case 0:
return mContext.getString(R.string.title_section1).toUpperCase(l);
case 1:
return mContext.getString(R.string.title_section2).toUpperCase(l);
}
return null;
}
}
1 Answer
Leon Mathis
23,404 PointsSOLVED! After some research, I had the MainActivity extends ActionBarActivity. Also fixed my Fragemnt.java issues.
public class MainActivity extends ActionBarActivity implements ActionBar.TabListener {
...as you were. :)
p.s. That feeling you get when you keep pushing forward and don't give up.
Leon Mathis
23,404 PointsLeon Mathis
23,404 Points