adjustpan not work in expandablelistview when click second time for the same edittext

前端 未结 2 536
别跟我提以往
别跟我提以往 2021-01-26 16:56

first time,click an edittext in expandablelistview,the whole layout scrolled ,and user can see edittext. then click softkeyboard finish to collapse softkeyboard and click this e

2条回答
  •  天涯浪人
    2021-01-26 17:27

    By many days spent,I found a solution. It is a hack.

    1. put you edittext wrapped in linearlayout.
    2. detect softkeyboard show by visiable layout change.

       public final void setKeyboardListener(final OnKeyboardVisibilityListener listener) {
      
       final View activityRootView = getWindow().getDecorView()
          .findViewById(android.R.id.content);
           activityRootView.getViewTreeObserver()
          .addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
      
            private final Rect r = new Rect();
            private boolean wasOpened;
      
            @Override
            public void onGlobalLayout() {
              activityRootView.getWindowVisibleDisplayFrame(r);
      
              int heightDiff = activityRootView.getRootView().getHeight()
                  - (r.bottom - r.top);
              boolean isOpen = heightDiff > 100;
      
              if (isOpen == wasOpened) {
                return;
              }
      
              wasOpened = isOpen;
              listener.onVisibilityChanged(isOpen);
            }
          });
         }
      
        public interface OnKeyboardVisibilityListener {
      
         void onVisibilityChanged(boolean visible);
          }
      
    3. when the softkeyboard show,pick up a textview in listview item or expandablelistview child item. then set it text for any thing, the whole view scrolled as normal! code like this:

      activity.setKeyboardListener(new OnKeyboardVisibilityListener() {
        @Override
      public void onVisibilityChanged(boolean visible) {
      if (visible) {
        Message message = new Message();
        message.what = 999;
        handler.sendMessage(message);
        }
       }
      });
      private Handler handler = new Handler() {
       @Override
      public void handleMessage(Message msg) {
      if (msg.what == 999) {
        if (mDataMap.size() > 0) {
        for (int i = 0; i < expandablelistview.getChildCount(); i++) {
          View v = expandablelistview.getChildAt(i);
          TextView tvCannotSee = (TextView) v.findViewById(R.id.tv_cannot_see );
          if (tvCannotSee != null) {
            //this is the key hack to make adjuspan work! and scroll the whole view up as normal
            tvCannotSee.setText("this is an android bug");
            return;
            }
          }
         }
         return;
        }
       super.handleMessage(msg);
       }
      };
      
    4. this textview show invisble to user for proper purpose.if it is a expandablelistview and the edittext in childitem,the textview update must be in a childitem.

提交回复
热议问题