0

I have a big problem. My main activity file has defined like this:

@Override
public void onDrawerItemSelected(View view, int position) {
    SendPost fragment = null;
    switch (position) {
        case 0:
            SendPost sendpost = new SendPost();
            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
            transaction.setTransition(FragmentTransaction.TRANSIT_ENTER_MASK);
            transaction.replace(R.id.container_body,sendpost);
            transaction.addToBackStack(null);
            transaction.commit();
            Toast.makeText(getApplicationContext(), "index 0 clicked!", Toast.LENGTH_SHORT).show();

            break;
        case 1:
            Toast.makeText(getApplicationContext(), "index 1 clicked!", Toast.LENGTH_SHORT).show();
            break;
        case 2:
            Toast.makeText(getApplicationContext(), "index 2 clicked!", Toast.LENGTH_SHORT).show();
            break;
        default:
            break;
    }
}

I want to load a simple fragment with the below code. my xml file comes at the bottom.

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:gravity="start"
    tools:context="com.soshia.paad.volleycustomlistview.MainActivity"
    android:orientation="vertical">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar" />

        <android.support.v7.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignTop="@+id/main_activity_for_draver"
            android:id="@+id/recy_for_main_activity"
            android:clipToPadding="false"
            android:paddingBottom="60dp"

            android:scrollbars="vertical"

            >


        </android.support.v7.widget.RecyclerView>

    </LinearLayout>

    <FrameLayout
        android:id="@+id/container_body"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        tools:ignore="Suspicious0dp">

    </FrameLayout>
</LinearLayout>


<fragment
    android:id="@+id/fragment_navigation_drawer"

    android:layout_width="@dimen/nav_drawer_width"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:layout="@layout/fragment_navigation_drawer"
    tools:layout="@layout/fragment_navigation_drawer"
    android:name="com.soshia.paad.FragmentDrawer" >

</fragment>

my activity:

public class MainActivity extends AppCompatActivity implements FragmentDrawer.FragmentDrawerListener

and my fragment xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.soshia.paad.SendPost"
android:background="@color/web_sormeii_color"
>

<!-- TODO: Update blank fragment layout -->
<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="سلام"
    android:textSize="80dp"
    android:gravity="center_horizontal|center_vertical"

    />

and my fragment code

public class SendPost extends Fragment {

public SendPost() {
    // Required empty public constructor
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_send_post, container, false);


    // Inflate the layout for this fragment
    return rootView;
}

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
}

@Override
public void onDetach() {
    super.onDetach();
}}

But I can not understand why the scroll doesn't work. I searched this site a lot but I couldn't find the solution. I am in a hurry. Please explain it to me with details. Yours. After running the program, nothing happens and the previous fragment stays in its place. I think fragments don't move.

Mohammadreza Khatami
  • 1,444
  • 2
  • 13
  • 27

0 Answers0