ZhipSoft.com
    冬去春来
        郑重声明:本Blog纯属个人学习、工作需要,记录相关资料。请不要发表任何有人身攻击的言论,谢谢!!www.ZhipSoft.com
posts - 94,comments - 149,trackbacks - 0

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.sqliteshowdemo);
  setTitle("查看日记");
   
  //设置Edit Text只读--start
  showTitle.setOnFocusChangeListener(focus_listener_noIM);
  showTitle.setOnTouchListener(touch_listener_noIM);
  showContent.setOnFocusChangeListener(focus_listener_noIM);
  showContent.setOnTouchListener(touch_listener_noIM);
  //设置Edit Text只读--end
 
 }

/*
  * 设置Edit Text只读
  */
 private void hideIM(View edt){
        try {
            InputMethodManager im = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
            IBinder  windowToken = edt.getWindowToken();
            if(windowToken != null) {
                im.hideSoftInputFromWindow(windowToken, 0);
            }
        } catch (Exception e) {
            Log.e("HideInputMethod", "failed:"+e.getMessage());
        }
    }

 /*
  * 设置Edit Text只读
  */
    private OnFocusChangeListener focus_listener_noIM = new OnFocusChangeListener(){
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus==true) {
                hideIM(v);
            }
        }
    };

 /*
  * 设置Edit Text只读
  */
    private OnTouchListener touch_listener_noIM = new OnTouchListener(){
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if(event.getAction()==MotionEvent.ACTION_DOWN) {
                hideIM(v);
            }
            return false;
        }
    };

XML文件中EditText属性:
        android:singleLine="true"
        android:ellipsize="none"
        android:editable="false"
        android:inputType="none"

        本Blog纯属个人学习、工作需要,记录相关资料。请不要发表任何有人身攻击的言论,谢谢! www.zhipsoft.cn
posted on 2011-01-25 17:17 ZhipSoft 阅读(1142) 评论(0)  编辑  收藏 所属分类: AndRoid

只有注册用户登录后才能发表评论。


网站导航: