This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Call Instance of View (Switch) located in Adapter's ViewHolder in the Activity that utilizes Adapter  RSS feed

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way for me to get an instance of the switch in my Adapter, in my Activity?

I created an instance of my Adapter's ViewHolder in my Activity:


Then I set up an onClickListener for the switch in my Activity's onCreate method:


However, I am getting a NullPointerException on the Switch. What am I missing?
 
Ranch Hand
Posts: 570
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean you want to use the switch in your Activity where the switch is declared in Adapter ?
 
Adam Wentz
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

John Joe wrote:You mean you want to use the switch in your Activity where the switch is declared in Adapter ?



Yes, the Switch is a View of the row layout for my RecyclerView. I want to be able to add an onClickListener to it in my Activity instead of doing it in the Adapter.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!