set Read Only for EditText, TextView - Android User Interface

Android examples for User Interface:TextView

Description

set Read Only for EditText, TextView

Demo Code


//package com.java2s;

import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;

public class Main {
    public static void setReadOnly(final EditText view,
            final boolean readOnly) {
        view.setFocusable(!readOnly);/* w  w w.  j  a  va2  s. c o m*/
        view.setFocusableInTouchMode(!readOnly);
        view.setClickable(!readOnly);
        view.setLongClickable(!readOnly);
        view.setCursorVisible(!readOnly);
    }

    public static void setReadOnly(final TextView view,
            final boolean readOnly) {
        view.setFocusable(!readOnly);
        view.setFocusableInTouchMode(!readOnly);
        view.setClickable(!readOnly);
        view.setLongClickable(!readOnly);
        view.setCursorVisible(!readOnly);
    }

    public static void setReadOnly(final Button view, final boolean readOnly) {
        view.setFocusable(!readOnly);
        view.setFocusableInTouchMode(!readOnly);
        view.setClickable(!readOnly);
        view.setLongClickable(!readOnly);
        view.setCursorVisible(!readOnly);
    }

    public static void setReadOnly(final ImageButton view,
            final boolean readOnly) {
        view.setEnabled(!readOnly);
    }
}

Related Tutorials