У меня есть следующий код:
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();
}
}
Не знаю почему, но Android Studio подчеркивает следующую строку: FragmentTransaction ft = getFragmentManager().beginTransaction();
и пишет:
несовместимые типы,Требуется: android.support.v4.app.FragmentTransaction Найдено: android.app.FragmentTransaction
Попытка изменить:
android.support.v4.app.FragmentTransaction
on:
android.app.FragmentTransaction
Но в этом случае он отклоняет следующую строку:
ft.replace(R.id.content_frame, fragment);
и пишет:
Неверный 2-й тип аргумента
Может быть, это из-за расширений Activity (возможно, все было бы нормально с AppCompat, но я могу 'изменить, как будто я знаю, тема, которую я использую в своем приложении, не совместима с Appcompat)