简体   繁体   中英

Why my SetHint in xamarin android does not work?

I set the hint programmatically for a purpose edittext.SetHint("MyHint"); but it does not work.

namespace MhylesApp
{
    [Activity(Label = "ToExistingCustomer"/*, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, ScreenOrientation = ScreenOrientation.Landscape*/)]
    public class ToExistingCustomer : Android.Support.V7.App.AppCompatActivity
    {
        private EditText edittext;
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.ExistingCustomer);
            edittext= FindViewById<EditText>(Resource.Id.qty);
            edittext.SetHint("My Hint");
        }
    }
}

The SetHint() method takes a resource as an argument. Instead of hard-coding a string, go to Resources> Values> strings.xml and add:

<string name="my_hint">My Hint</string>

Then in your code, set

edittext.SetHint(Resource.String.my_hint);

Since you are using Mono.Droid its always good to remember that it is .Net based and to make it easier for .Net developers and to follow the .Net coding standards the get and set type methods are actually properties in Xamarin so your hint should be set like this:

  edittext.Hint = "Your text";

Goodluck

Feel free to revert if you have queries

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM