3

The app won't build properly as I think its looking for fragment cruisespeed_Fragment which is actually a fragmentactivity when building a navigation drawer. The reason cruisespeed_Fragment is a fragment activity is it is a tabbed layout which I put together using this tutorial.

In MainActivity.java:

@Override
public void onNavigationDrawerItemSelected(int position) {

    Fragment objFragment = null;

    switch (position) {
        case 0:
            objFragment = new project_Fragment();
            break;
        case 1:
            objFragment = new cruisespeed_Fragment();
                break;
        case 2:
            objFragment = new satflow_Fragment();
            break;
        case 3:
            objFragment = new network_Fragment();
            break;
        }
    // update the main content by replacing fragments
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction()
            .replace(R.id.container, objFragment)
            .commit();
}

And in cruisespeed_Fragment.java:

public class cruisespeed_Fragment extends FragmentActivity implements ActionBar.TabListener {

private ViewPager viewPager;
private CSPagerAdapter mAdapter;
private ActionBar actionBar;
// Tab titles
private String[] tabs = {"Top Rated", "Games", "Movies"};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Initilization
    viewPager = (ViewPager) findViewById(R.id.pager);
    actionBar = getActionBar();
    mAdapter = new CSPagerAdapter(getFragmentManager());

    viewPager.setAdapter(mAdapter);
    actionBar.setHomeButtonEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Adding Tabs
    for (String tab_name : tabs) {
        actionBar.addTab(actionBar.newTab().setText(tab_name)
                .setTabListener(this));
    }
}

The error I'm getting is Error:(62, 31) error: incompatible types required: Fragment found: cruisespeed_Fragment

For some reason logcat isn't outputting anything at the moment but once I get that sorted again I will update.

Jonny Wright
  • 1,119
  • 4
  • 20
  • 38

2 Answers2

0

FragmentActivity extends Activity and NOT Fragment you need to have your _Fragment() classes extend from some form of Fragment

Charles Durham
  • 2,445
  • 16
  • 17
0

Without testing your code personally it's difficult for me to speak conclusively, but my understanding is that FragmentActivity is an Activity used to host an android.support.v4.app.Fragment, not an android.app.Fragment

As such, you wont be able to launch a FragmentActivity with the following code:

FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
        .replace(R.id.container, objFragment)
        .commit();

You will need to use an Intent. Also, ensure you are not accidentally mixing support Fragments with regular Fragments. This post goes into good detail on the differences.

Community
  • 1
  • 1
PPartisan
  • 8,173
  • 4
  • 29
  • 48