Try to hide keyboard

Hello, I have trouble.
I trying to hide keyboard, when I tap outside EditText, but it doesn't work
What's wrong with my code?

`using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Content.PM;
using Android.Views.InputMethods;

namespace MurakamiKiev
{
[Activity(Label = "Murakami", Icon = "@drawable/logo", Theme = "@android:style/Theme.Black.NoTitleBar", ScreenOrientation = ScreenOrientation.Portrait)]
public class Cart2Activity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);

        // Create your application here
        Window.SetSoftInputMode(SoftInput.StateAlwaysHidden);



        SetContentView(Resource.Layout.Cart2);
        ImageButton nadislati = FindViewById<ImageButton>(Resource.Id.nadislatiButton);
        ImageButton logo = FindViewById<ImageButton>(Resource.Id.logoButton);
        ImageButton previous = FindViewById<ImageButton>(Resource.Id.previousButton);
        ImageButton home = FindViewById<ImageButton>(Resource.Id.homeButton);
        ImageButton menu = FindViewById<ImageButton>(Resource.Id.menuButton);

        EditText misto = FindViewById<EditText>(Resource.Id.misto);
        InputMethodManager imm = (InputMethodManager)GetSystemService(Context.InputMethodService);
        imm.HideSoftInputFromWindow(misto.WindowToken, 0);


        nadislati.Click += delegate
        {
            var intent31 = new Intent(this, typeof(Cart3Activity));
            StartActivity(intent31);
        };
        previous.Click += delegate
        {
            var intent32 = new Intent(this, typeof(CartActivity));
            StartActivity(intent32);
        };
        //Otslezivaem click po knopke "Home" i perehodim na glavnuu
        home.Click += delegate
        {
            var intent33 = new Intent(this, typeof(MainActivity));
            StartActivity(intent33);
        };
        //Otslezivaem click po knopke "Logo" i perehodim na glavnuu
        logo.Click += delegate
        {
            var intent34 = new Intent(this, typeof(MainActivity));
            StartActivity(intent34);
        };
        menu.Click += delegate
        {
            var intent51 = new Intent(this, typeof(MenuTopActivity));
            StartActivity(intent51);

        };
    }




}
}

`

Tagged:

Posts

  • manoharbonalamanoharbonala INMember ✭✭

    Implement key board hiding logic in OnTouchEvent()

    public override bool OnTouchEvent(MotionEvent e)
    {
    InputMethodManager imm = (InputMethodManager)GetSystemService(InputMethodService);
    imm.HideSoftInputFromWindow(CurrentFocus.WindowToken, 0);
    return base.OnTouchEvent(e);
    }

  • Eugene.2980Eugene.2980 USMember
    edited September 2015

    I realize like this:

    one.Click += delegate { InputMethodManager imm = (InputMethodManager)GetSystemService(Context.InputMethodService); imm.HideSoftInputFromWindow(misto.WindowToken, 0); };

Sign In or Register to comment.