• 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
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

Access handler placed in onBindViewHolder

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I have a handler in my onBindViewHolder method which looks like this:



I am trying to call it from another method using: handler.sendEmptyMessage(0);
But symbol "handler" cannot be resolved.

I tried creating a field for "handler" but this is not useful.

How can I connect my handler to my method?
 
Rancher
Posts: 4936
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tried creating a field for "handler" but this is not useful.  


Please explain.


symbol "handler" cannot be resolved.


The variable: handler needs to be in scope where you are trying to access it.
 
Nat Thomas
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I declare the variable "handler" with other variables at the top, below the class name, the app compiles but nothing happens when "handler" is called.

One other possibility would be if I could refer to MyViewHolder (holder) outside of OnBindViewHolder. Then I would not need to put my Handler in OnBindViewHolder. Is this possible?
 
Norm Radder
Rancher
Posts: 4936
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

nothing happens when "handler" is called.


handler is a reference to an object, not a method that can be called.  Please explain what method you are trying to call and why you think that method is not being called.
 
Nat Thomas
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:

nothing happens when "handler" is called.


handler is a reference to an object, not a method that can be called.  Please explain what method you are trying to call and why you think that method is not being called.



Hi again, and thanks for your help.

I use "handler.sendEmptyMessage(0);" in another method. Technically, my TextView should turn to black as soon as Handler is called, but this does not happen.

Do you need me to provide more code or am I making sense?

 
Nat Thomas
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nat MadHatter wrote:

Norm Radder wrote:

nothing happens when "handler" is called.


handler is a reference to an object, not a method that can be called.  Please explain what method you are trying to call and why you think that method is not being called.



Hi again, and thanks for your help.

I use "handler.sendEmptyMessage(0);" in another method. Technically, my TextView should turn to black as soon as Handler is called, but this does not happen.

Do you need me to provide more code or am I making sense?



Oh, sorry, I've just realized I already gave that info earlier on. Let me try and explain better what I mean.
 
Nat Thomas
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a method that checks in realtime whether words exists:



This method, checkIfExists(), looks like this:



The problem is that my TextView is inside onBindViewHolder, and the only way I can access it to change it is by putting my handler inside onBindViewHolder too.

I hope this makes more sense now.
 
Norm Radder
Rancher
Posts: 4936
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where is the variable: handler defined?
Where is the reference made to that variable?  The variable needs to be in scope to be accessed.
 
Nat Thomas
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So basicallly I found out that my handler works if I simply want to send out a Toast message. So the problem is actually not with the handler itself.
The problem is this:



This works (first five letters turn to black) but :



This doesn't work (first five letters remain white).

Do you have any ideas what might be the problem?
Thanks!
 
Norm Radder
Rancher
Posts: 4936
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where is the code that will cause the  handleMessage method to be called?
 
Nat Thomas
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:Where is the code that will cause the  handleMessage method to be called?



It's "handler.sendEmptyMessage(0);" in this method:


 
Nat Thomas
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This method is called here:

 
Norm Radder
Rancher
Posts: 4936
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there just one handler variable that is being used?  Hard to tell with the code snippets.

Where is the code that causes the run method to be called?
 
Nat Thomas
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:Is there just one handler variable that is being used?  Hard to tell with the code snippets.

Where is the code that causes the run method to be called?



Yes, just the one.
 
Nat Thomas
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nat Thomas wrote:

Norm Radder wrote:Is there just one handler variable that is being used?  Hard to tell with the code snippets.

Where is the code that causes the run method to be called?



Yes, just the one.



The code that causes the run method to be called is just above your post.
 
Norm Radder
Rancher
Posts: 4936
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The code that causes the run method to be called is just above your post.


Where?  What post (copy post's time stamp) and what line in the code in that post?
 
The City calls upon her steadfast protectors. Now for a tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic