Passing Value from One activity to another activity in android app using C# with Xamarin Archives - Tech Insights https://reactconf.org/category/passing-value-from-one-activity-to-another-activity-in-android-app-using-c-with-xamarin/ Unveiling Tomorrow's Tech Today, Where Innovation Meets Insight Mon, 02 Jan 2017 16:42:00 +0000 en-US hourly 1 https://wordpress.org/?v=6.6.2 https://i0.wp.com/reactconf.org/wp-content/uploads/2023/11/cropped-reactconf.png?fit=32%2C32&ssl=1 Passing Value from One activity to another activity in android app using C# with Xamarin Archives - Tech Insights https://reactconf.org/category/passing-value-from-one-activity-to-another-activity-in-android-app-using-c-with-xamarin/ 32 32 230003556 Passing Value from One activity to another activity in android app using C# with Xamarin https://reactconf.org/passingvaluefromoneactivitytoanotheractivityinandroidappusingcsharpswithxamarin/ https://reactconf.org/passingvaluefromoneactivitytoanotheractivityinandroidappusingcsharpswithxamarin/#respond Mon, 02 Jan 2017 16:42:00 +0000 https://reactconf.org/passingvaluefromoneactivitytoanotheractivityinandroidappusingcsharpswithxamarin/       In this tutorial I will show you how to pass value from one activity to another activity in Android app using C# with Xamarin. Steps  ·         Create new …

The post Passing Value from One activity to another activity in android app using C# with Xamarin appeared first on Tech Insights.

]]>
      In this tutorial I will show you how to pass value from one activity to another activity in Android app using C# with Xamarin.

Steps 

  • ·         Create new project

  • ·                Expand resource folder
  •            Click on layout folder  as shown below image
  • ·          Create two layout  Main.axml  and  Datascreen.axml.
  • ·       Create two activity  Mainactivity and activity2.

In Main.axml paste below code
<?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>
    <EditText
        android:layout_width=match_parent
        android:layout_height=wrap_content
        android:id=@+id/editText1 />
    <Button
        android:text=Send Second Activity
        android:layout_width=match_parent
        android:layout_height=wrap_content
        android:id=@+id/button1 />
</LinearLayout>

DataScreen.axml  paste below code.
<?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>
    <EditText
        android:layout_width=match_parent
        android:layout_height=wrap_content
        android:id=@+id/editText2 />
    <Button
        android:text=Send to Main Activity
        android:layout_width=match_parent
        android:layout_height=wrap_content
        android:id=@+id/button2 />
</LinearLayout>
MainActivity.cs
public class MainActivity : Activity
    {
        Button btnclick;
        EditText textpass;
        protected override voidOnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            // Set our view from the “main” layout resource
            SetContentView (Resource.Layout.Main);
              btnclick = FindViewById<Button>(Resource.Id.button1);
             textpass = FindViewById<EditText>(Resource.Id.editText1);
            btnclick.Click += btn_click;
            string name = Intent.GetStringExtra(“Name”);
            textpass.Text = ” , “ + name;
        
           
        }
        private voidbtn_click(object sender, EventArgs e)
        { 
            if (textpass.Text != “”)
            {
                
                Intent j = new Intent(this, typeof(Activity2));
              
                j.PutExtra(“Name”, textpass.Text.ToString());
               
                StartActivity(j);
            }
            else
            {
                Toast.MakeText(this, “Please Enter Value”, ToastLength.Short).Show();
            }
        }
    }
Activity2.cs
public class Activity2 : Activity
    {
        Button btnsclick;
        EditText textpass2;
        protected override voidOnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            // Create your application here
            SetContentView(Resource.Layout.DataScreen);
            btnsclick = FindViewById<Button>(Resource.Id.button2);
            textpass2 = FindViewById<EditText>(Resource.Id.editText2);
            string name = Intent.GetStringExtra(“Name”);
            textpass2.Text = ” , “ + name;
            btnsclick.Click += btns_click;
           
        }
        private voidbtns_click(object sender, EventArgs e)
        {
            if (textpass2.Text != “”)
            {
                Intent j = new Intent(this, typeof(MainActivity));
                j.PutExtra(“Name”, textpass2.Text.ToString());
                StartActivity(j);
            }
            else
            {
                Toast.MakeText(this, “Please Enter Value”, ToastLength.Short).Show();
            }
           
        }
    }


The post Passing Value from One activity to another activity in android app using C# with Xamarin appeared first on Tech Insights.

]]>
https://reactconf.org/passingvaluefromoneactivitytoanotheractivityinandroidappusingcsharpswithxamarin/feed/ 0 2248