Why text2.Text = "message" is not working in my code ?
I want to use it in a function as per the below source code.
I developed in Visual Stduio with Mono for android in C#.
The Source code:
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
namespace ChatClient_Android
{
[Activity(Label = "ChatClient_Android", MainLauncher = true, Icon = "@drawable/icon")]
public class MainChat : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
EditText text2 = FindViewById<EditText>(Resource.Id.text2);
}
private void recieved()
{
text2.Text = "mesage"; // The text2 does not existe in this context
}
}
}
EditText text2is declared not global but to the method. PutEditText text2;in the class.Should be like this :