PagerAdapter 内の画像ボタンの可視性を変更したいと考えています。id を介して instantiateItem のレイアウトの一部を参照できないようです。完全なレイアウトしか参照できません。これは奇妙ですが、ID を使用して Web ビューを参照できるようです。
どうすればこれにアプローチできますか? これは私がやろうとしていることですが、以下に示す最後の行でヌル ポインター例外が発生しています。
public Object instantiateItem(View collection, int position) {
ImageButton btnRight = (ImageButton) findViewById(R.id.buttonright);
ImageButton btnLeft = (ImageButton) findViewById(R.id.buttonleft);
if (position == 0) {
resLayout = R.layout.the_webview;
urltoload = theUrls[position];
resId = R.id.webview0;
btnLeft.setVisibility(View.INVISIBLE);
View view = inflater.inflate(resLayout, null);
...
if (position != 2) {
mainWebView = (WebView) view.findViewById(resId);
mainWebView.getSettings().setJavaScriptEnabled(true);
mainWebView.loadUrl(urltoload);
}
((ViewPager) collection).addView(view, 0);
return view;
}
それに応じて可視性を設定する位置が必要なので、onCreate でこれを行うことはできません。通常のアダプターでは getView を使用できますが、PagerAdapter では使用できません。
また、ハンドラーを介して独自の UI 更新スレッドを作成できることも読みましたが、この場合はどうすればよいですか?
ありがとう。