SlideMenuLayout slide to not just layout, but an activity

113 Views Asked by At

Hello I managed to reproduce the code from this tutorial https://www.youtube.com/watch?v=HrLLnoa9Zd4&index=32&list=WL&t=330s.

But then I decided to add something simple like a button to the left slide that changes its text. I created a new activity with SetContentView(Resource.Layout.Left); and wrote the click event to the button. When I start the program ,though, I click on the button and nothing happens. I figured out that the activity is actually not called and what I see is only the layout.

My question is if there is a way to call the activity that I wrote when I slide to the left?

main layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.jkb.slidemenu.SlideMenuLayout
    android:minWidth="25px"
    android:minHeight="25px"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/slideMenuLayout1"
    app:contentToggle="true"
    app:contentAlpha="0.5"
    app:parallax="false"
    app:slideMode="both">

    <include layout="@layout/Left" />
    <include layout="@layout/Right" />
    <include layout="@layout/MainView" />   

  </com.jkb.slidemenu.SlideMenuLayout>
</RelativeLayout>  

left layout

<Button
    android:text="Button"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/leftBtn" />
<TextView
    android:text="Slide Left"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minWidth="25px"
    android:minHeight="25px"
    android:id="@+id/leftText" />  

left activity

Button btn = FindViewById<Button>(Resource.Id.leftBtn);
TextView text = FindViewById<TextView>(Resource.Id.leftText);
btn.Click += (sender, e) => { text.Text = "text is chaged"; };
2

There are 2 best solutions below

0
Georgi Yakov On BEST ANSWER

I got. I can use fragments instead of include.
The main.axml will look like this

<com.jkb.slidemenu.SlideMenuLayout
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/slideMenuLayout1"
app:contentToggle="true"
app:contentAlpha="0.5"
app:parallax="false"
app:slideMode="both">

   <fragment
    class="NameSpace.FragmentName"  //it is important to write the namespace and gragment name
    android:layout = "@layout/Left" //here you choose the layout you want to render
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/RightFragment" />

      //repeat the same for the Right and Main view 

</com.jkb.slidemenu.SlideMenuLayout>  

And the fragment.cs you just need this

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
         base.OnCreateView(inflater, container, savedInstanceState);

          View  view = inflater.Inflate(Resource.Layout.YourLayout, container, false);
    }
2
Cherry Bu - MSFT On

I do one demo about using SlideMenuLayout, but I cannot reproduce your issue, and I can change button text of content_menu_left view, here is my sample:

main.axml:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" 
android:orientation="vertical"  
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.jkb.slidemenu.SlideMenuLayout 
    android:id="@+id/mainSlidemenu"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    app:contentAlpha="0.5" 
    app:contentToggle="true" 
    app:parallax="false" 
    app:slideMode="both">

    <include layout="@layout/content_menu_left"/>
    <include layout="@layout/content_menu_right"/>
    <TextView                   
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:text="this is slide menu main layout" 
        android:textSize="22sp" />  

    </com.jkb.slidemenu.SlideMenuLayout>
</LinearLayout>

left-menu:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:text="left menu" 
    android:textSize="22sp" />

<Button 
    android:id="@+id/btn1" 
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:text="left menu" />
</LinearLayout>
Button button1;
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        // Set our view from the "main" layout resource
        //SetContentView(Resource.Layout.activity_main);
        SetContentView(Resource.Layout.activity_main);

        button1 = (Button)FindViewById(Resource.Id.btn1);
        button1.Click += Button1_Click;
    }

    private void Button1_Click(object sender, System.EventArgs e)
    {
        button1.Text = "this is test";
    }