• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic