aspose file tools*
The moose likes Android and the fly likes Toast context inside onFocusChangeListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "Toast context inside onFocusChangeListener" Watch "Toast context inside onFocusChangeListener" New topic
Author

Toast context inside onFocusChangeListener

Muhammad Imad Qureshi
Ranch Hand

Joined: Sep 13, 2005
Posts: 238
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
Piyush Patel
Ranch Hand

Joined: Feb 24, 2009
Posts: 127

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

Joined: Sep 13, 2005
Posts: 238
"this" is not working because I am inside a listener.
Piyush Patel
Ranch Hand

Joined: Feb 24, 2009
Posts: 127

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

Joined: Sep 13, 2005
Posts: 238
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: Toast context inside onFocusChangeListener