为什么键盘在我调用pagerAdapter.notifyDataSetChanged()时隐藏; ?? 我正在使用https://github.com/romannurik/Android-WizardPager。 这个库使用ViewPager。当我调用notifyDataSetChanged并且软件键盘可见时,键盘隐藏。
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;
}
}
答案 0 :(得分:0)
快速和脏修复可能是通过调用强制键盘显示:
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
或
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
答案 1 :(得分:0)
尝试一下,这应该可行
//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);