• 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:

Toast context inside onFocusChangeListener

 
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am inside onFocusChangeListenerMethod inside my activity class. How do I get access to my activity object to use in Toast.makeText() method? What other ways are there to display an error message (user has entered incorrect text). Here is my code
I have commented the code in "else" part that I want to fix.

Thanks
Imad
 
Ranch Hand
Posts: 127
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,Imad

Toast.makeText(getApplicationContext(), "Invalid Value(s) Entered in \"Values\" Field", Toast.LENGTH_LONG).show();



i hope your application is extending Activity (any of android activity) then, instead of writing getApplicationContext() try following this will work.


 
Muhammad Imad Qureshi
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"this" is not working because I am inside a listener.
 
Piyush Patel
Ranch Hand
Posts: 127
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Imad, can you show class code and Log (error) here,that will help us to find the problem solution.
one solution: create class variable Context and set it inside onCreate(); use this variable in your Toast.makeText(getApplicationContext(), "Invalid Value(s) Entered in \"Values\" Field", Toast.LENGTH_LONG).show();

 
Muhammad Imad Qureshi
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply. I resolved it with the following code. I think you are right. I should be able to use getApplicationContext() too. But this is what I did.

 
I can't take it! You are too smart for me! Here is the 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