Listview with edittext - auto scroll on “next”

后端 未结 2 436
走了就别回头了
走了就别回头了 2020-12-20 14:39

I have a ListView with one EditText on each row (in addition to a couple of non-editable TextView\'s). When I\'m editing the text in the EditText, the soft keyboard has \"N

2条回答
  •  旧时难觅i
    2020-12-20 15:42

    I have no idea about holder, so I found a way to do without it. Inside getView add onEditorActionListener.

    EditText editView = (EditText)convertView;
    editView.editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(final TextView view, int actionId, KeyEvent event){
               if(actionId == EditorInfo.IME_ACTION_NEXT){
                int lastPos = lv.getLastVisiblePosition();
                lv.smoothScrollToPosition(position + 1);
                if(position >= lastPos){
                    lv.postDelayed(new Runnable(){
                       @Override
                        public void run(){
                             final int posTop = lv.getFirstVisiblePosition();
                             TextView nextView = (EditText)lv.getChildAt(position - posTop + 1);
                             nextView.requestFocus();
                        }
                     }, 200);
                }
                //Delay is not required
                else{              
                    final int posTop = lv.getFirstVisiblePosition();
                    TextView nextView = (EditText)lv.getChildAt(position - posTop + 1);
                    nextView.requestFocus();
                }
              }
          }
    });
    

提交回复
热议问题