Method getString() in Overlay, how ?

Put your problem here if it does not fit any of the other categories.

Method getString() in Overlay, how ?

Postby cassianotartari » Fri Oct 10, 2008 3:29 am

Hi,

I have a problem to show a Toast in my class that extends Overlay. The problem is on the text
passed as a parameter to show in the window, I want that this text stay in strings.xml but I can't simply pass R.string.txt or getString(R.string.txt), the method getString() can't be used in Overlay.

I'm using m5-r15

Thanks ;)


Sorry with my english
public class pessoa {
private String nome = "Cassiano Tartari";
private String url = "www.cassianotartari.eng.br"
}
User avatar
cassianotartari
Developer
Developer
 
Posts: 28
Joined: Thu Aug 28, 2008 3:42 pm

Top

Postby plusminus » Fri Oct 10, 2008 5:14 am

Hello cassianotartari,

there is a Context passed to your View in its Constructor (or when you manually create it, pass 'this' of your Activity as it extends Context). Example:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class MyView extends View{
  2.  
  3.      protected final Context mCtx;
  4.  
  5.  
  6.  
  7.      public MyView(final Context ctx){
  8.  
  9.           this.mCtx = ctx;
  10.  
  11.      }
  12.  
  13. }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Opps you said Overlay not View. So just pass 'this' of your Activity as it extends Context to the Constructor of the Overlay and store it like above.

Best Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby cassianotartari » Fri Oct 10, 2008 2:07 pm

Thanks a lot ! Works fine
public class pessoa {
private String nome = "Cassiano Tartari";
private String url = "www.cassianotartari.eng.br"
}
User avatar
cassianotartari
Developer
Developer
 
Posts: 28
Joined: Thu Aug 28, 2008 3:42 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 14 guests