porthfind
porthfind

Reputation: 1619

Android: Can't type in an EditText

I don't know why but I can't type/write on the EditText when I try to do it. The EditText's cursor doesn't appear and the keyboard when appears is not the numeric one. I have the following part of code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.android.asminhasdespesas.Meta_1Activity">


    <TextView android:text="Test:"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TableLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <TableRow>


            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:inputType="number"
                android:textColor="#000000"
                android:cursorVisible="true"
                android:ems="10"
                android:id="@+id/editTextMeta"
                android:layout_gravity="center_vertical"
                android:layout_weight="1"
                android:focusable="true"
                android:focusableInTouchMode="true" />

            <TextView
                android:text="€"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

        </TableRow>


        <TableRow>

            <Button
                android:id="@+id/buttonNaoColocar"
                android:text="Cancel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:onClick="onClick"/>

            <Button
                android:id="@+id/buttonOk"
                android:text="Ok"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:onClick="onClick"/>

        </TableRow>

    </TableLayout>

</LinearLayout>

I tried to solve this situation with "android:cursorVisible="true" or even "android:textColor="#000000", I also tried "android:focusable="true" "android:focusableInTouchMode="true"" but the problem persists, I can't type on EditText.

Can you please help me?

Upvotes: 13

Views: 25903

Answers (6)

Amrit Kumar
Amrit Kumar

Reputation: 1

if you are using virtual device then just simply wipe data and try again. it will work.

Upvotes: 0

Rajesh N
Rajesh N

Reputation: 6673

I had same issue then i removed android:focusableInTouchMode="true" from parent view(LinearLayout) of editbox and its working fine

Upvotes: 2

Ananya Roy
Ananya Roy

Reputation: 33

I'm new to the field of Android Development. Well, I was facing the same problem. So I just set

android:text=""

this caused the text to appear when I typed it in the EditText. I am not sure why did this work, but I am just speaking from personal experience

Upvotes: 3

Zinc
Zinc

Reputation: 1002

Check if you have a setOnKeyListener wherever you have the edittext and be sure that you return false if you don't need the event, for example:

OnKeyListener listener = new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                //Do something
                return true;
            }
            return false;
        }
    };

Upvotes: 5

user1241388
user1241388

Reputation: 147

As others have said, the code you have above looks like it wouldn't cause a problem. That leads me to think when you're making the object in your java file(s) you might be screwing with a setting. I would text where the problem stems from by eliminating a lot of the tags from your edit text field, and make it as minimal as possible such as

 <EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="number"
    android:id="@+id/editTextMeta"
 />

Upvotes: 0

Simas
Simas

Reputation: 44118

You probably want something like:

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="number"
        android:textColor="#000000"
        android:cursorVisible="true"
        android:ems="10"
        android:id="@+id/editTextMeta"
        android:layout_gravity="center_vertical"
        android:focusable="true"
        android:focusableInTouchMode="true" />
  • Removed weight (unused)

Upvotes: 5

Related Questions