Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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.
 
Then YOU must do the pig's work! Read this tiny ad. READ IT!
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!