0

I need to on the start of the Activity my EditText has the readonly mode so I do it like below:
xml

<layout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto">

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:paddingBottom="@dimen/edge_offset"
            android:paddingLeft="@dimen/edge_offset"
            android:paddingStart="@dimen/edge_offset"
            android:paddingRight="@dimen/edge_offset"
            android:paddingEnd="@dimen/edge_offset"
            android:paddingTop="@dimen/edge_offset"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <EditText
                android:id="@+id/hometask_edt"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:inputType="textMultiLine"
                android:gravity="top|start"
                android:scrollHorizontally="false"
                android:hint="@string/label_summary"/>

        </android.support.design.widget.TextInputLayout>

    </android.support.design.widget.CoordinatorLayout>

</layout>

Activity

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mBinder = DataBindingUtil.setContentView(this, R.layout.activity_hometask);
    // Setup EditText
    mBinder.hometaskEdt.setInputType(InputType.TYPE_NULL);
}

When the user clicks a menu item the EditText must be editable again. I try to make it so:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();

    if (itemId == R.id.action_edit) {
        mBinder.hometaskEdt.setInputType(InputType.TYPE_CLASS_TEXT);
        mBinder.hometaskEdt.invalidate();

        return true;
    }

    return super.onOptionsItemSelected(item);
}

But, of course, it doesn't work =( What do I doing wrong?

Denis Sologub
  • 7,277
  • 11
  • 56
  • 123
  • 1
    Please look at: [Link 1](http://stackoverflow.com/questions/660151/how-to-replicate-androideditable-false-in-code) and [Link 2](http://stackoverflow.com/questions/6555455/how-to-set-editable-true-false-edittext-in-android-programmatically) – Bogdan Kobylynskyi May 11 '17 at 20:44
  • @BogdanKobylinsky, but it has a lot of solutions...I can't get what can I use to disable the user input only from these solutions (To the user doesn't see the touch keyboard and cursor but to he can select and copy a text)? – Denis Sologub May 11 '17 at 20:50
  • Have you considered using the `enabled` attribute instead (obviously, set it to `false`)? – oaskamay May 11 '17 at 20:51
  • @oaskamay, it was marked as deprecated. – Denis Sologub May 11 '17 at 20:52
  • 1
    @Шах, consider [this answer](http://stackoverflow.com/a/4341748/668148) – Bogdan Kobylynskyi May 11 '17 at 21:12
  • As I understood it's hard to keep "paste" and "cut" options only. So I just will add a separate button "copy". Thank you for help! – Denis Sologub May 11 '17 at 21:20
  • What about `editable`? – oaskamay May 12 '17 at 13:56
  • @oaskamay Sorry, I told about `editable`. `enabled` works perfect but it disables scrolling also. – Denis Sologub May 12 '17 at 13:59
  • @Шах can you try setting `editable` to `false`, and also removing the `inputType` attribute as well? Apparently `editable=false` only works if no `inputType` is supplied. – oaskamay May 12 '17 at 14:53

1 Answers1

-1
  1. Put this in the manifest inside that perticular Activity tag android:windowSoftInputMode="stateHidden"
vikas khot
  • 31
  • 2