How to programmatically set maxLength in Android TextView?

后端 未结 11 1801
心在旅途
心在旅途 2020-11-29 17:06

I would like to programmatically set maxLength property of TextView as I don\'t want to hard code it in the layout. I can\'t see any set

11条回答
  •  心在旅途
    2020-11-29 17:40

         AlertDialog.Builder builder = new AlertDialog.Builder(this);
                        builder.setTitle("Title");
    
    
                        final EditText input = new EditText(this);
                        input.setInputType(InputType.TYPE_CLASS_NUMBER);
    //for Limit...                    
    input.setFilters(new InputFilter[] {new InputFilter.LengthFilter(3)});
                        builder.setView(input);
    

提交回复
热议问题