I want to change visibility of my image buttons within my PagerAdapter. It doesn't seem like I can refer to parts of a layout in instantiateItem through id, I can only refer to the full layout. This is strange though, because it seems that I can still refer to my webviews through id.
How do I approach this? This is what I'm trying to do, but I'm getting a null pointer exception at the last line shown below:
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;
}
I need the position to set visibility accordingly, so I cannot do this in onCreate. I know for a normal adapter, I can use getView, but I cannot use it for PagerAdapter.
I have also read that I can just create my own UI update thread through handlers, but how do I do that in this case?
Thanks.