在我的應用程序中,我使用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