码迷,mamicode.com
首页 > 其他好文 > 详细

EditText动态转换只读/编辑状态

时间:2015-10-08 18:18:59      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:

 1 public class MyActivity extends Activity
 2 {
 3     private KeyListener listener;
 4     private EditText editText;
 5 
 6     public void onCreate(...)
 7     {
 8         editText = ... // Get EditText from somewhere
 9         listener = editText.getKeyListener(); // Save the default KeyListener!!!
10         editText.setKeyListener(null); // Disable input
11     }
12 
13     // When you click your button, restore the default KeyListener
14     public void buttonClickHandler(...)
15     {
16         editText.setKeyListener(listener);
17     }
18 }

 

Basically, you first save the EditText‘s default KeyListener before you call setKeyListener(null). Then, when you click your button, you call setKeyListener again, passing the default listener you previously saved.

 

以上是来自http://stackoverflow.com/questions/10933056/edit-text-key-listener问题中rainai的回答

好用。

EditText动态转换只读/编辑状态

标签:

原文地址:http://www.cnblogs.com/turtle920/p/4861593.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!