notifyDataSetChanged and keyboard

故事扮演 提交于 2021-02-08 10:09:15

问题


Why keyboard hiding when I call pagerAdapter.notifyDataSetChanged(); ?? I'm using https://github.com/romannurik/Android-WizardPager . This library using ViewPager. And when i call notifyDataSetChanged and software keyboard is visible, keyboard hiding.

public class WizardAdapter extends FragmentStatePagerAdapter {

        private int cutOffPage = -1;
        private BaseFragment primaryItem;

        public WizardAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int i) {
            return pages.get(i).createFragment();
        }

        @Override
        public int getItemPosition(Object object) {
            if (object instanceof WizardFragment) {
                Page page = ((WizardFragment) object).getData();
                if (!pages.contains(page)) {
                    return POSITION_NONE;
                }
            }

            if (object == primaryItem) {
                // Re-use the current fragment (its position never changes)
                return POSITION_UNCHANGED;
            }

            return POSITION_NONE;
        }

        @Override
        public void setPrimaryItem(ViewGroup container, int position, Object object) {
            super.setPrimaryItem(container, position, object);

            primaryItem = (BaseFragment) object;
        }

        @Override
        public int getCount() {
            int count = 0;

            if (cutOffPage >= 0) {
                count = Math.min(cutOffPage + 1, pages.size());
            } else if (pages != null) {
                count = pages.size();
            }

            return count;
        }

        public int getCutOffPage() {
            return cutOffPage;
        }

        public void setCutOffPage(int cutOffPage) {
            this.cutOffPage = cutOffPage;
        }
    }

回答1:


Give this a try, this should work

//Import this
import android.view.inputmethod.InputMethodManager;

//Create object
private InputMethodManager imm;

imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_IMPLICIT_ONLY);



回答2:


A quick and dirty fix might be to force the keyboard to appear by calling:

((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);

Or

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);


来源:https://stackoverflow.com/questions/24650506/notifydatasetchanged-and-keyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!