Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

How to set Enabled state of button whenever a text field is edited or changed?

$
0
0

Hey guys,

In my app I have a set of EditText fields that each get populated from a database. Underneath these fields I have a button labeled 'Save Item' that is disabled by default until you start making changes to any of the fields above. I need to make it so that it fires my EnableSaveItemButton method no matter which EditText field you click on and start editing.

I know that I need it to respond to the AfterTextChanged property, but I only know how to make it work when there is just one field. I know I need to place all of my EditText fields into an array, but need help with that. Please see my code below:

    EditText assetTypeText = null;
    EditText modelText = null;
    EditText manufacturerText = null;

    protected override void OnCreate(Bundle bundle) 
        {
            base.OnCreate(bundle);

            // Set our view
            SetContentView(Resource.Layout.Detail);
            _imgView = FindViewById<ImageView>(Resource.Id.imageView1);

                    assetTypeText = FindViewById<EditText> (Resource.Id.assetTypeEditText);
                    modelText = FindViewById<EditText> (Resource.Id.modelEditText);

                    manufacturerText = FindViewById<EditText> (Resource.Id.manufacturerEditText);
                    manufacturerText.AfterTextChanged += delegate(object sender, Android.Text.AfterTextChangedEventArgs e) {
                    EnableSaveItemButton();
                };

                    Button buttonSave = FindViewById<Button>(Resource.Id.Detail_SaveButton);
                buttonSave.Enabled = false;
                buttonSave.Click += delegate
                {
                            //bla bla bla
                }


    //further below
    public void EnableSaveItemButton ()
            {
                Button buttonSave = FindViewById<Button>(Resource.Id.Detail_SaveButton);
                buttonSave.Enabled = true;
            }

Any help is appreciated, thanks!


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>