EditText Typing not working

KishoreKishore INMember
edited January 2014 in Xamarin.Android

Hey everyone,

I have a problem related to EditText field.

Here is my custom edit text xml.

        <MyProject.CabinFontEditText
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="left"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp"
            android:layout_marginRight="10dp"
            android:layout_marginLeft="10dp"
            android:adjustViewBounds="true"
            android:paddingTop="5dp"
            android:paddingLeft="7dp"
            android:text="Search here"
            android:layout_gravity="center_vertical|center_horizontal"
            android:textSize="11sp"
            android:background="@drawable/rounded_edittext"
            android:layout_weight="1"
            android:textColor="#D3D3D3"
            android:id="@+id/searchText" />

"Search here" text appears properly in the edittext field. Once i delete it and try to type new string it is not working.

I could the the following in "Application output" tab in Xamarin studio.

  [InputEventConsistencyVerifier] KeyEvent: ACTION_UP but key was not down.
  [InputEventConsistencyVerifier]   in [email protected]
  [InputEventConsistencyVerifier]   0: sent at 1804241000000, KeyEvent { action=ACTION_UP, keyCode=KEYCODE_SHIFT_LEFT, scanCode=42,        metaState=0, flags=0x8, repeatCount=0, eventTime=1804241, downTime=1804041, deviceId=0, source=0x101 }
  [InputEventConsistencyVerifier]   -- recent events --
  [InputEventConsistencyVerifier]   1: sent at 1804241000000, (unhandled) KeyEvent { action=ACTION_UP, keyCode=KEYCODE_L, scanCode=38,  metaState=META_SHIFT_ON|META_SHIFT_LEFT_ON, flags=0x8, repeatCount=0, eventTime=1804241, downTime=1804041, deviceId=0, source=0x101 }
  [InputEventConsistencyVerifier]   2: sent at 1804041000000, (unhandled) KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_L, scanCode=38, metaState=META_SHIFT_ON|META_SHIFT_LEFT_ON, flags=0x8, repeatCount=0, eventTime=1804041, downTime=1804041, deviceId=0, source=0x101 }

Does anyone know what does it mean?

I appreciate any help.

Posts

  • CortezCortez USMember ✭✭✭

    Hello @Kishore!

    Without any testing i can suggest you to set for your editext a hint attribute. With this you can set a temporary text for your edittext("Search here"), but you don't need to delete it. If the edittext will have focus then the "Search here" text will be disappear and you can type your text without deleting any character.

  • KishoreKishore INMember

    Hi @Cortez,

    Thank you very much for your reply.

    I tried what you said. Now i don't have to delete (ie, cursor appears at the beginning of the edittext on click) .But i couldn't be able to type in it. (ie, when i type nothing is appearing in the EditText.)

    Any Idea?

    Thanks.

  • CortezCortez USMember ✭✭✭

    Is this EditText inside of a listview item? If you type in it the soft keyboard disappear too ?

  • KishoreKishore INMember
    edited January 2014

    The EditText is in the Custom Header. Soft Keyboard is not even appearing.

    The whole xml code for header:

        <?xml version="1.0" encoding="utf-8"?>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            style="@style/CustomTitleStyle">
            <TableLayout
                android:layout_width="match_parent"
                android:layout_height="42dp"
                android:background="#3A3A3A">
                <ViewSwitcher
                    android:id="@+id/ViewSwitcher"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent">
                    <TableRow
                        android:layout_height="fill_parent"
                        android:layout_width="fill_parent"
                        android:gravity="center_horizontal">
                        <ImageView
                            android:src="@drawable/Icon"
                            android:layout_width="100dp"
                            android:layout_height="fill_parent"
                            android:scaleType="centerInside"
                            android:adjustViewBounds="true"
                            android:layout_gravity="center_vertical|center_horizontal"
                            android:gravity="left"
                            android:paddingLeft="10dp"
                            android:layout_weight="1"
                            android:id="@+id/imageView2" />
                        <ViewSwitcher
                            android:id="@+id/ImageTextSwitcher"
                            android:layout_width="290dp"
                            android:adjustViewBounds="true"
                            android:layout_height="fill_parent">
                            <LinearLayout
                                android:id="@+id/view1"
                                android:layout_width="290dp"
                                android:adjustViewBounds="true"
                                android:layout_height="match_parent">
                                <MyProject.MyProjectTextView
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:gravity="center"
                                    android:layout_gravity="center_vertical|center_horizontal"
                                    android:text="Test"
                                    android:layout_weight="1"
                                    android:textColor="#8ACAE1"
                                    android:id="@+id/textview1" />
                            </LinearLayout>
                            <LinearLayout
                                android:id="@+id/view2"
                                android:adjustViewBounds="true"
                                android:layout_width="290dp"
                                android:layout_height="match_parent">
                                <ImageView
                                    android:src="@drawable/stampedeWallHead"
                                    android:layout_width="150dp"
                                    android:layout_height="match_parent"
                                    android:layout_marginTop="12dp"
                                    android:layout_marginBottom="12dp"
                                    android:scaleType="centerInside"
                                    android:adjustViewBounds="true"
                                    android:layout_gravity="center_vertical|center_horizontal"
                                    android:gravity="center"
                                    android:layout_weight="1"
                                    android:id="@+id/imageView2" />
                            </LinearLayout>
                        </ViewSwitcher>
                        <ImageView
                            android:src="@drawable/notification"
                            android:layout_width="100dp"
                            android:layout_height="fill_parent"
                            android:gravity="right"
                            android:scaleType="centerInside"
                            android:adjustViewBounds="true"
                            android:paddingRight="10dp"
                            android:layout_gravity="center_vertical|center_horizontal"
                            android:layout_weight="1"
                            android:id="@+id/settingsicon" />
                    </TableRow>
                    <TableRow
                        android:layout_height="fill_parent"
                        android:layout_width="fill_parent"
                        android:gravity="center_horizontal">
                        <ImageView
                            android:src="@drawable/close"
                            android:layout_width="100dp"
                            android:layout_height="fill_parent"
                            android:scaleType="centerInside"
                            android:layout_marginTop="11dp"
                            android:layout_marginBottom="11dp"
                            android:adjustViewBounds="true"
                            android:layout_gravity="center_vertical|center_horizontal"
                            android:paddingLeft="10dp"
                            android:layout_weight="1"
                            android:id="@+id/close" />
                        <ViewSwitcher
                            android:id="@+id/TextSwitcher"
                            android:layout_width="290dp"
                            android:adjustViewBounds="true"
                            android:layout_height="fill_parent">
                            <LinearLayout
                                android:id="@+id/view3"
                                android:layout_width="290dp"
                                android:adjustViewBounds="true"
                                android:layout_height="match_parent">
                                <MyProject.CabinFontEditText
                                    android:layout_width="fill_parent"
                                    android:layout_height="fill_parent"
                                    android:gravity="left"
                                    android:layout_marginTop="8dp"
                                    android:layout_marginBottom="8dp"
                                    android:layout_marginRight="10dp"
                                    android:layout_marginLeft="10dp"
                                    android:adjustViewBounds="true"
                                    android:paddingTop="5dp"
                                    android:paddingLeft="7dp"
                                    android:hint="Looking for someone?"
                                    android:layout_gravity="center_vertical|center_horizontal"
                                    android:textSize="11sp"
                                    android:background="@drawable/rounded_edittext"
                                    android:layout_weight="1"
                                    android:textColor="#D3D3D3"
                                    android:id="@+id/searchText" />
                            </LinearLayout>
                            <LinearLayout
                                android:id="@+id/view4"
                                android:layout_width="290dp"
                                android:adjustViewBounds="true"
                                android:layout_height="match_parent">
                                <MyProject.MyProjectTextView
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:gravity="center"
                                    android:layout_gravity="center_vertical|center_horizontal"
                                    android:text="YOUR ACCOUNT"
                                    android:layout_weight="1"
                                    android:textColor="#8ACAE1"
                                    android:id="@+id/textview1" />
                            </LinearLayout>
                        </ViewSwitcher>
                        <ImageView
                            android:src="@drawable/search_icon"
                            android:layout_width="100dp"
                            android:layout_height="fill_parent"
                            android:gravity="right"
                            android:paddingRight="10dp"
                            android:layout_gravity="center_vertical|center_horizontal"
                            android:layout_weight="1"
                            android:id="@+id/search" />
                    </TableRow>
                </ViewSwitcher>
            </TableLayout>
            <LinearLayout
                android:id="@+id/changeBg"
                android:layout_weight="1"
                android:layout_height="3dp"
                android:background="#8ACAE1"
                android:layout_marginBottom="0dp"
                android:layout_width="fill_parent" />
        </LinearLayout>
    

    It is a bit complicated.

  • KishoreKishore INMember
    edited January 2014

    @Cortez

    Or Is it something about the custom edittext font?

    Here is the code i used

        public class CabinFontEditText : EditText
            {
                private const string Tag = "TextView";
    
                protected CabinFontEditText(IntPtr javaReference, JniHandleOwnership transfer) 
                    : base(javaReference, transfer)
                {
                }
    
                public CabinFontEditText(Context context) 
                    : this(context, null)
                {
                }
    
                public CabinFontEditText(Context context, IAttributeSet attrs) 
                    : this(context, attrs, 0)
                {
                }
    
                public CabinFontEditText(Context context, IAttributeSet attrs, int defStyle) 
                    : base(context, attrs, defStyle)
                {
                    var a = context.ObtainStyledAttributes(attrs,
                        Resource.Styleable.CustomFonts);
                    var customFont = a.GetString(Resource.Styleable.CustomFonts_customFont);
                    SetCustomFont(customFont);
                    a.Recycle();
                }
    
                public void SetCustomFont(string asset)
                {
                    Typeface tf;
                    try
                    {
                        tf = Typeface.CreateFromAsset(Context.Assets, "fonts/cabin-regular-webfont.ttf");
                    }
                    catch (Exception e)
                    {
                        Log.Error(Tag, string.Format("Could not get Typeface: {0} Error: {1}", asset, e));
                        return;
                    }
    
                    if (null == tf) return;
    
                    var tfStyle = TypefaceStyle.Normal;
                    if (null != Typeface) //Takes care of android:textStyle=""
                        tfStyle = Typeface.Style;
                    SetTypeface(tf, tfStyle);
                }
            }
    
Sign In or Register to comment.