android


How to Change Visibility of an ImageButton within a PagerAdapter?


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.
Try this, where "itemLayout" is your layout :
View thisLayout = inflater.inflate(R.layout.itemLayout, null);
btnLeft = (ImageButton) thisLayout.findViewById(R.id.buttonleft);
<do stuff with btnLeft>
((ViewPager) collection).addView(thisLayout);
return thisLayout;
Regarding your Q on updating the UI on a thread, check out runOnUiThread here
The answer to this is right here: http://mobile.tutsplus.com/tutorials/android/android-user-interface-design-horizontal-view-paging/comment-page-1/#comment-14065
Apparently you must refer to the Relative or Linear layout that your button resides in or else findViewById will not be able to find what you are referring to.

Related Links

How to get all CheckBoxes from all rows in a ListView
cursor selected position is not working in android
Is there an Android equivalent of iOS' MWPhotoBrowser SDK?
Can we start IntentService from another App?
Error inflating class android.widget.DatePicker on android version 7.0
workaround for async call to read from Firebase
Show a null in my Toast
How determine if system dialog is appear?
Android Map Fragment overflowing and some elements not showing
Node.js https/ssl debugging on Android
Sending a Notification When a Change Happens at Firebase Database with a Service
How to access amazon product detail in android app through amazon product link
How to correctly setColor in a custom view
How can I mute audio YouTubeAndroidPlayerAPI?
Paytm Integration not working android
Building Video Streaming App Using Native vs Hybrid Approach? [closed]

Categories

HOME
batch-file
go
gridview
developer-tools
mstest
devise
shiro
r-googlesheets
cublas
rds
tvos
discrete-mathematics
performancepoint
p2p
project
owin
emoji
line
onedrive-api
zerobrane
capistrano3
dynamic-sql
google-container-registry
digital-signature
production
charles
resourcebundle
game-theory
slidetoggle
bringtofront
jaws
utorrent
database-comparison
deltaspike
clickjacking
login-script
sql-delete
openerp-7
projects-and-solutions
railstutorial.org
kill
visa
vmware-fusion
wmp
http-request
android-checkbox
importerror
stylecop
strftime
facebook-social-plugins
nanoc
xbmc
facebook-pixel
aquamacs
boxing
subnet
boo
pdf-conversion
mouseleave
juice-ui
usart
watch-os-2
rspec2
nservicebus5
createprocess
nio2
spring-retry
character-replacement
sapi
sciruby
xvim
fuelcms
dock
pax-exam
toolkit
slash
atoi
google-refine
snoop
teamcity-9.1
boost-program-options
cocos3d
teaspoon
nsmenu
build-script
ss7
gae-quotas
ie8-compatibility-mode
code-duplication
jeromq
dtmf
mvc-editor-templates
superscrollorama
argouml
subgraph
josql
isa-swizzling
luabind
role
jquery-tools
listactivity
tournament
cgbitmapcontextcreate
cuteeditor
dataform
presentation-layer
folding
filesystemobject
firefox-3

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App