android - get applicationContext in TextView.setText() -


i'm building textview subclass change text inserted in android:text. instance, want capitalize whole text but, make sure needed, need access application instance (i have boolean tells if must or not capitalized).

i implemented subclass:

public class uppertextview extends textview {  private context context;  public uppertextview(context context) {     super(context);     this.context = context; }  public uppertextview(context context, attributeset attrs, int defstyle) {     super(context, attrs, defstyle);     this.context = context; }  public uppertextview(context context, attributeset attrs) {     super(context, attrs);     this.context = context; }  @override public void settext(charsequence text, buffertype type) {     //i nullpointerexception here since var context null     context applicationcontext = context.getapplicationcontext();      if (text != null && applicationcontext instanceof myapplication && applicationcontext.douppercase()) {          myapplication myapp = (myapplication) applicationcontext;         myapp.getlanguagescontroller().getlocalizedstring(text.tostring().touppercase());     }     super.settext(text, type); } } 

in layout, have declared this

            <my.package.uppertextview             android:id="@+id/foo"             android:text="bar"/> 

i nullpointerexception when invoking context.getapplicationcontext().

did came across this?

i think should try :

this.getcontext().getapplicationcontext() 

this should not return null pointer exception.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -