imeOptions not working for CustomEditText

63 views Asked by At

I need to set imeOptions on my CustomEditText. But the imeOptions is not available.

My CustomEditText:

public class CustomEditText extends AppCompatEditText {
    private Context context;

    public CustomEditText(Context context) {
        super(context);
        this.context = context;
    }

    public CustomEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
    }

    public CustomEditText(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
    }
}
2

There are 2 answers

0
AskNilesh On BEST ANSWER

Your CustomEditText code is woking fine in my devive

You need to set android:inputType="text" with android:imeOptions="actionNext"

You can set inputType and imeOptions as per your requirement

Check this below example

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.example.nilesh.testapp.CustomEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:imeOptions="actionNext"
        android:inputType="text" />

    <com.example.nilesh.testapp.CustomEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:imeOptions="actionNext"
        android:inputType="text" />

    <com.example.nilesh.testapp.CustomEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:imeOptions="actionNext"
        android:inputType="text" />

    <com.example.nilesh.testapp.CustomEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:imeOptions="actionNext"
        android:inputType="text" />

    <com.example.nilesh.testapp.CustomEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:imeOptions="actionNext"
        android:inputType="text" />

</LinearLayout>
0
Hitesh Sarsava On

make method to set imeOption like below :

public class CustomEditText extends AppCompatEditText {
    private Context context;

    public CustomEditText(Context context) {
        super(context);
        this.context = context;
        setImeOption();
    }

    public CustomEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        setImeOption();
    }

    public CustomEditText(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        setImeOption();
    }

private void setImeOption() {
                this.setImeOptions(EditorInfo.IME_ACTION_NEXT);
            }

    }