在我的应用程序中,我使用viewPager给我很好的swipey视图。我想让键盘隐藏在其中的两页中,但总是在一页上显示,我有一个文本框。不能让Android软键盘出现/隐藏使用viewpager
我试过各种方式让键盘显示,但它不工作。我想我必须在错误的地方调用显示键盘代码。
@Override
public Object instantiateItem(View collection, int position)
{
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = null;
if(position==0){
layout=inflater.inflate(R.layout.other, null);
//new PC().create(layout, context);
((InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(collection.getWindowToken(), 0);
}else if(position==1){
layout=inflater.inflate(R.layout.main, null);
new BlurayRemote().create(layout,context);
((InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(collection.getWindowToken(), 0);
}else if(position==2){
layout=inflater.inflate(R.layout.text, null);
new TextInput().create(layout,context);
((InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInputFromInputMethod(collection.getWindowToken(), 0);
}
((ViewPager) collection).addView(layout);
return layout;
}
任何帮助将是伟大的,因为它是让我疯了!
此外,您的活动将在您旋转屏幕时重新创建,因此上下文将会更改;如此一来,您的pageadaptor将保持不再存在的上下文,并导致内存泄漏! – Raunak