Я пытаюсь создать фрагмент, который охватит половину активности. Я создал фиктивный XML, но не могу перейти на него. Я создал фрагмент через New -> Fragment -> Fragment (Blank). Я не редактировал код созданного фрагмента класса, только XML.
Это мой XML:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="90pt"
android:layout_height="match_parent"
tools:context=".MenuFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Menu"
android:textSize="45dp"
android:paddingLeft="10dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BLA"
android:textSize="45dp"
android:paddingLeft="10dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BLA"
android:textSize="45dp"
android:paddingLeft="10dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BLA"
android:textSize="45dp"
android:paddingLeft="10dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BLA"
android:textSize="45dp"
android:paddingLeft="10dp"
/>
</LinearLayout>
Здесь я хочу перейти к фрагменту. Это нужно сделать нажатием кнопки.
findViewById(R.id.Menu).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "Menu fragment goes here!", Toast.LENGTH_SHORT).show();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
MenuFragment menuFragment = new MenuFragment();
fragmentTransaction.replace(android.R.id.content, menuFragment);
fragmentTransaction.commit();
}
});
Это проблема:
Wrong 2nd argument type. Found:
'com.example.pogolemotoproektce.MenuFragment', required:
'android.app.Fragment' less...
Inspection info:
replace
(int,
android.app.Fragment)
in FragmentTransaction cannot be applied
to
(int,
com.example.pogolemotoproektce.MenuFragment)
происходит в следующей строке:
fragmentTransaction.replace(android.R.id.content, menuFragment);