I have the following code:
package asus.example.com.notes1;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.ShareActionProvider;
public class MainActivity extends Activity {
private void selectItem(int position){
Fragment fragment;
switch (position){
case 1:
fragment = new PizzaFragment();
break;
case 2:
fragment = new PastaFragment();
break;
case 3:
fragment = new StoresFragment();
break;
default:
fragment = new TopFragment();
}
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.content_frame, fragment);
ft.addToBackStack(null);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.commit();
}
}
I don't know why, but Android Studio underlines the following line: FragmentTransaction ft = getFragmentManager().beginTransaction();
and writes:
incompatible types. Required: android.support.v4.app.FragmentTransaction Found: android.app.FragmentTransaction
Tried to change:
android.support.v4.app.FragmentTransaction
on:
android.app.FragmentTransaction
But in such case, it undelines the following line:
ft.replace(R.id.content_frame, fragment);
and writes:
Wrong 2nd arguement type
Maybe, this is because of extends Activity (maybe everything 'd be normal with AppCompat, but I can't change, as if I know, theme which I use in my app isn't compatible with Appcompat)