Make EditText ReadOnly

前端 未结 22 1272

I want to make a read-only EditText view. The XML to do this code seems to be android:editable=\"false\", but I want to do this in code.

H

22条回答
  •  一向
    一向 (楼主)
    2020-12-04 19:04

    I had no problem making EditTextPreference read-only, by using:

    editTextPref.setSelectable(false);
    

    This works well when coupled with using the 'summary' field to display read-only fields (useful for displaying account info, for example). Updating the summary fields dynamically snatched from http://gmariotti.blogspot.com/2013/01/preferenceactivity-preferencefragment.html

    private static final List keyList;
    
    static {
        keyList = new ArrayList();
        keyList.add("field1");
        keyList.add("field2");
        keyList.add("field3");
    }
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);
    
        for(int i=0;i

提交回复
热议问题