zoukankan      html  css  js  c++  java
  • ListView中弹出软键盘时,EditText失去焦点的问题

    问题描述: 在ListView中,点击EditText获得焦点时,会重新调用getView,此时EditText会失去焦点。

    方案: 

    定义一个全局的mCurrentIndex,记录刷新前是哪一项被点击量。给EdtiText设置onTouchListener,在这里设置mCurrentIndex的值。然后在

    getView里面进行判断,如果是之前的选中项,设置它的焦点。看代码

     1 // 定义变量,记录刷新前获得焦点的EditText所在的位置
     2 int mCurrentTouchedIndex = -1;
     3 
     4 // 在getView中进行判断
     5 public View getView(int position, View convertView, Viewgroup parent) {
     6     ...
     7     // 设置触摸事件(别想着用OnClickListener)
     8     focusEt.setOnTouchListener(new OnEditTextTouched(position));
     9     focusEt.clearFocus();
    10     if (position == mCurrentTouchedIndex) {
    11         // 如果该项中的EditText是要获取焦点的
    12         focusEt.requestFocus();
    13     }
    14     return convertView;
    15 }
    16 
    17 // ListView中EditText的触摸事件
    18 private class OnEditTextTouched implement OnTouchListener {
    19     private int position;
    20 
    21     public OnEditTextTouched(int position) {
    22         this.position = position;
    23     }
    24 
    25     @override
    26     public boolean onTouch(View v, MotionEvent event) {
    27         if (event.getAction() == MotionEvent.ACTION_UP) {
    28             mCurrentTouchedIndex = position;
    29         }
    30         return false;
    31     }
    32 }
  • 相关阅读:
    自绘标题栏
    显示驱动相关 -- DrvEscape和ExtEscape
    Delphi 直接打印代码(不需要装打印机驱动)
    在TCanvas上画背景透明的矩形
    写作套路中的立功,立言,立德
    python入门(Python和Pycharm安装)
    delphi CxGrid用法总结(63问)
    如何安装inf类型驱动程序 inno
    PHP-SQL Server
    Exchange Tech Issues 参考网站
  • 原文地址:https://www.cnblogs.com/ivan-aldrich/p/4244295.html
Copyright © 2011-2022 走看看